Friday, July 7, 2017

How to add Multiple validation group to the same control ?



In some conditions we may need to validate a controls based on the different conditions consider the below example in which we are validating the same dropdown list from two different validation group Here we are using the  Page_ClientValidate('your validation group name') method which will accept the validation group name as input
  

Example:- 

 
<form id="form1" runat="server">
        <asp:Button Text="First" runat="server" ValidationGroup="firstVG" />
        <asp:Button Text="Second" runat="server" ValidationGroup="secondVG"  OnClientClick="return Check(); " />

        <asp:DropDownList runat="server" ValidationGroup="first" ID="ddl">
            <asp:ListItem Text="--Select--" Value="-1" />
            <asp:ListItem Text="A" />
            <asp:ListItem Text="B" />
        </asp:DropDownList>
        <asp:RequiredFieldValidator ErrorMessage="*" Display="Dynamic" ForeColor="Red" ControlToValidate="ddl" runat="server"  InitialValue="-1" ValidationGroup="firstVG"/>

    </form>

JavaScript File :- 

 

    <script type="text/javascript">
        function Check() {

            var isValid = false;
            isValid = Page_ClientValidate('secondVG');
            if (isValid) {
                isValid = Page_ClientValidate('firstVG');
            }

            return isValid;

        }
    </script>

WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for 'jquery'. Please add a ScriptResourceMapping named jquery(case-sensitive).



After adding the built in validating controls like required field validator in my case I added a new web form and then after adding the required field validator controller in the form the form got compiled but after running we can see the above error on the browser. The solution is that  we need to add  a new key into to the web.config file under the <appSettings> section

In Web.config



  <appSettings>

    <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />

  </appSettings>

Friday, February 10, 2017

Could not load file or assembly 'Newtonsoft.Json' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

When we get the above error after updating the Newtonsoft.Json library from the NuGet package manager or installing it. The solution to the problem is that first delete all the reference from the project or delete the DLL files from the project and then try to install the library again and then check. It worked for me after updating the Newtonsoft.Json library from NuGet package manager console
Update-Package Newtonsoft.Json
Or try this
 Update-Package –reinstall Newtonsoft.Json

To send push notification's to IOS device

To send push notifications to the IOS devices from WCF service we need to first install the push sharp  and the Newtonsoft.Json library from the NuGet package manager. 

To install the push sharp from package manager console type the following command 
Install-Package PushSharp
https://www.nuget.org/packages/PushSharp/
To install the Newtonsoft.Json from package manager console type the following command
 Install-Package Newtonsoft.Json
https://www.nuget.org/packages/Newtonsoft.Json/9.0.2-beta2 

After installing the package write the following code to send the notifications.



using Newtonsoft.Json.Linq;
using PushSharp.Apple;

  public void IosPushNotifications()
        {
            var certificate = File.ReadAllBytes("Add your certificate location");
            var configuration = new PushSharp.Apple.ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Sandbox, certificate, "your certificate password");

            var ServiceBroker = new ApnsServiceBroker(configuration);

            string message = "Your message";
            ServiceBroker.Start();
            ServiceBroker.QueueNotification(new ApnsNotification
            {
                DeviceToken = "18545dd4eredf47834e4er4exxxxxxxxxxxxxxxxxxxxxxxxx",//your device token
                Payload = JObject.Parse("{'aps':{'badge':1,'sound':'oven.caf','alert':'" + message + "'}}")
            });

            ServiceBroker.Stop();
        }

Git Commands

Git Version   To check the git version Git -v       Git Clone To clone the repository, use the following command: Git clone [u...