Wednesday, September 14, 2016

LINQ to SQL protects from SQL-injection attacks

Q.How is LINQ to SQL protected from SQL-injection attacks?
A.SQL injection has been a critical danger for traditional SQL queries shaped by concatenating client input.
LINQ to SQL avoids sql injection by utilizing SqlParameter as a part of queries.
User information is transformed into parameter values.
This methodology keeps malicious commands from being utilized from customer input

Wednesday, August 31, 2016

How to Debug the Window service in Dotnet both C# and VB.Net

There Two ways you can debug the service

 First :

 Go to Service.Designer.vb page find below mentioned code and comment mentioned places, later create new instance of the class and call the main method check below code.
 --- VB.NET
 ' The main entry point for the process
    <MTAThread()> _
    <System.Diagnostics.DebuggerNonUserCode()> _
    Shared Sub Main()
        Comment/Uncomment --'Dim ServicesToRun() As System.ServiceProcess.ServiceBase

        ' More than one NT Service may run within the same process. To add
        ' another service to this process, change the following line to
        ' create a second service object. For example,
        '
        '   ServicesToRun = New System.ServiceProcess.ServiceBase () {New Service1, New MySecondUserService}
        '
        Comment/Uncomment --'ServicesToRun = New System.ServiceProcess.ServiceBase() {New UniDocBulkImportService}

        Comment/Uncomment --'System.ServiceProcess.ServiceBase.Run(ServicesToRun)

Dim objClsMain as New ClsMain() -- Create new instance for your main class in your service
objClsMain.MainMethod()         --- Call the Main method in above class where service start processing

    End Sub

 --- C#.NET
Go to Program.cs page find below mentioned code and comment mentioned places, later create new instance of the class and call the main method check below code.
static void Main()
        {
           Comment/Uncomment // ServiceBase[] ServicesToRun;
           Comment/Uncomment // ServicesToRun = new ServiceBase[]
            Comment/Uncomment //{
            Comment/Uncomment //    new Unidoc_CHAD_IN_Service()
           Comment/Uncomment // };
           Comment/Uncomment // ServiceBase.Run(ServicesToRun);
         clsMain ObjClsMain =new clsMain(); -- Create new instance for your main class in your service
ObjClsMain.MainMethod();  --- Call the Main method in above class where service start processing
         
        }
Second :

 Add new windows form to your service project right click on project and go to properties
 under ApplicationType ---> select WindowsFormApplication
 and UnderStartup project select Form1 so directlry debugger starts from Form1.
 same C# also.

Difference between Abstract Class and Interface

What is an Abstract Class?

An abstract class is a special kind of class that cannot be instantiated. it allows other classes to inherit from it. In simple words, if you inherit this class need to implement methods in this class.
Ex: Like in your project you have all the EDIT,DELETE,UPDATE and SELECT methods, if you want maintain to same hierarchies for all the classes then place these methods in abstract class and inherit this class in all your modules.
Real life example of Abstract : Mobile,TV,Watch and human body...... etc.


What is an Interface?

An interface is not a class. An interface has no implementation; Method without body, As one of the similarities to Abstract class, it is a contract that is used to define hierarchies for all subclasses.


Difference between them is
that a class can implement more than one interface but can only inherit from one abstract class. Since C# doesn’t support multiple inheritance, interfaces are used to implement multiple inheritance.

Abstract class  : static methods, main method and constructor.

Interface: no static methods, main method or constructor.

Tuesday, June 28, 2016

Validation with Regular expression


Validation code behind using Regularexpression class Regex 
//Calling method
value  = yourvalue(string,int or Email)
bool bCheck = NumberValidation(value);  - Calling method
bCheck  -- Return Value
if (bCheck == false)
{
 //not matching
}
Else
{
 //matching

}

1. Number validation  - Only numbers (1,2,3,...)

private bool NumberValidation(string value)
{
Regex regex = new Regex("^[0-9]*$");
if (regex.IsMatch(value))
{
countCheck = 0;
return true;
}
else
{
if (countCheck == 1 && tPalceholdervalue != "")
{
countCheck = 0;
MessageBox.Show("Only numbers may be entered here", "Restriction");
return false;
}
return false;
}
}

2. Alphanumeric  (combination numbers and alphabets )

private bool AlphNumeric(string value)
{
Regex regex = new Regex(@"[a-zA-Z0-9/'.]{1,40}");
if (regex.IsMatch(value))
{
countCheck = 0;
return true;
}
else
{
if (countCheck == 1 && tPalceholdervalue != "")
{
countCheck = 0;
MessageBox.Show("No Special Characters", "Restriction");
return false;
}
return false;
}
}

3.Email Validation

private bool EmailCheck(string value)
{

Regex regex = new Regex(@"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$");
if (regex.IsMatch(value))
{
countCheck = 0;
return true;
}
else
{
if (countCheck == 0 && tPalceholdervalue != "")
{
countCheck = 1;
MessageBox.Show("Ex: yourname@email.com", "Restriction");
return false;
}
return false;
}
}

4. Name Validation
private bool NameValidation(string value)
{
value = value.TrimEnd();
Regex regex = new Regex(@"^[0-9a-zA-Z ]+$");
if (regex.IsMatch(value))
{
countCheck = 0;
return true;
}
else
{
if (countCheck == 1 && tPalceholdervalue != "")
{
countCheck = 0;
MessageBox.Show("Special Characters are not allowed", "Restriction");
return false;
}
return false;
}
}

5. Date Validation 
private bool DateValidation(string value)
{
Regex regex = new Regex(@"\d{1,2}\/\d{1,2}/\d{4}");
if (regex.IsMatch(value))
{
countCheck = 0;
return true;
}
else
{
if (countCheck == 1 && tPalceholdervalue != "")
{
countCheck = 0;
MessageBox.Show("Date format : MM/DD/YYYY", "Restriction");
return false;
}
return false;
}
}

6. Boolean Validation

private bool BooleanValidation(string value)
{
if (value.ToUpper() == "YES" || value.ToUpper() == "NO")
{
countCheck = 0;
return true;
}
else
{
if (countCheck == 1 && tPalceholdervalue != "")
{
countCheck = 0;
MessageBox.Show("Ex: Yes or No", "Restriction");
return false;
}
return false;
}
}




Monday, June 27, 2016

Total Registration form validations with Jquery 2016

Total Registration for all validations with Jquery


Design the form

<div style="height: 894px" >
   
        <asp:Panel ID="Panel1" runat="server"
          style="z-index: 1; left: 44px; top: 58px; position: absolute; height: 836px; width: 844px" >
            <asp:TextBox ID="txtDob" runat="server"
                style="z-index: 1; left: 232px; top: 108px; position: absolute; width: 123px; margin-top: 0px; height: 24px;"
                Font-Size="12pt" ReadOnly="True"></asp:TextBox>
            <cc1:CalendarExtender ID="txtDob_CalendarExtender" runat="server"
                BehaviorID="txtDob_CalendarExtender" TargetControlID="txtDob" PopupButtonID="ImageButton1"/>
            <asp:TextBox ID="txtFn" TabIndex ="1" runat="server"
                style="z-index: 1; left: 232px; top: 33px; position: absolute; width: 153px;"
                Font-Size="12pt"></asp:TextBox>
            <asp:TextBox ID="txtLn"  TabIndex ="2" runat="server"
                style="z-index: 1; left: 587px; top: 33px; position: absolute; width: 152px;"
                Font-Size="12pt"></asp:TextBox>
            <asp:TextBox ID="txtCnPwd" runat="server" TextMode="Password" TabIndex="23"
                style="z-index: 1; left: 236px; top: 739px; position: absolute; height: 24px; width: 151px;"
                Font-Size="12pt"></asp:TextBox>
            <asp:Label ID="Label1" runat="server" Font-Bold="True"
                style="z-index: 1; left: 414px; top: 35px; position: absolute; height: 23px; width: 148px"
                Text="LAST NAME"></asp:Label>
            <asp:Label ID="Label2" runat="server" Font-Bold="True"
                style="z-index: 1; left: 411px; top: 147px; position: absolute; height: 23px; width: 148px"
                Text="MOTHER NAME"></asp:Label>
            <asp:Label ID="Label3" runat="server" Font-Bold="True"
                style="z-index: 1; left: 413px; top: 71px; position: absolute; height: 24px; width: 110px"
                Text="GENDER"></asp:Label>
            <asp:Label ID="Label4" runat="server" Font-Bold="True"
                style="z-index: 1; left: 27px; top: 106px; position: absolute; height: 23px; width: 148px; margin-top: 2px"
                Text="DATE OF BIRTH"></asp:Label>
            <asp:Label ID="Label5" runat="server" Font-Bold="True"
                style="z-index: 1; left: 24px; top: 36px; position: absolute; height: 23px; width: 148px"
                Text="FIRST NAME"></asp:Label>
            <asp:Label ID="Label7" runat="server" Font-Bold="True"
                style="z-index: 1; left: 30px; top: 739px; position: absolute; height: 28px; width: 183px"
                Text="CONFORM PASSWORD"></asp:Label>
            <asp:Label ID="Label8" runat="server" Font-Bold="True"
                style="z-index: 1; left: 34px; top: 434px; position: absolute; height: 23px; width: 148px; margin-top: 0px;"
                Text="STATE"></asp:Label>
            <asp:Label ID="Label9" runat="server" Font-Bold="True"
                style="z-index: 1; left: 35px; top: 697px; position: absolute; height: 23px; width: 148px"
                Text="PASSWORD"></asp:Label>
            <asp:TextBox ID="txtEid" runat="server" Font-Size="12pt" TabIndex="20"                                
               
               
                style="z-index: 1; left: 235px; top: 577px; position: absolute; height: 24px; width: 152px;"></asp:TextBox>
            <asp:TextBox ID="txtPwd" runat="server" Font-Size="12pt" TextMode="Password" TabIndex="22"
               
               
               
               
                style="z-index: 1; left: 236px; top: 694px; position: absolute; margin-top: 0px; height: 24px; width: 152px;"></asp:TextBox>
            <asp:Label ID="Label10" runat="server" Font-Bold="True"
                style="z-index: 1; left: 33px; top: 579px; position: absolute; height: 23px; width: 148px; margin-top: 0px;"
                Text="EMAIL ID"></asp:Label>
            <asp:Label ID="Label29" runat="server" Font-Bold="True"
                style="z-index: 1; left: 25px; top: 71px; position: absolute; height: 23px; width: 148px"
                Text="TITLE"></asp:Label>
            <asp:Button ID="SaveBtn" runat="server" Font-Bold="True"
                onclick="SaveBtn_Click"
                style="z-index: 1; left: 184px; top: 791px; position: absolute; width: 68px; height: 28px"
                Text="SAVE" />
            <asp:TextBox ID="txtPrmntOtherSt" runat="server"
               
                style="z-index: 1; left: 413px; top: 431px; position: absolute; height: 24px; width: 159px"></asp:TextBox>
            <asp:DropDownList ID="ddPrmntState" runat="server" TabIndex="17"
               
               
               
                style="z-index: 1; left: 235px; top: 433px; position: absolute; height: 24px; width: 137px">
                <asp:ListItem>Select</asp:ListItem>
                <asp:ListItem>Andhra Pradesh</asp:ListItem>
                <asp:ListItem>Karnataka</asp:ListItem>
                <asp:ListItem>Maharastra</asp:ListItem>
                <asp:ListItem Value="0">Other</asp:ListItem>
            </asp:DropDownList>
            <asp:TextBox ID="txtPrmntDistrict" runat="server" TabIndex="16"
               
               
               
                style="z-index: 1; left: 587px; top: 390px; position: absolute; height: 24px;"></asp:TextBox>
            <asp:TextBox ID="txtPrmntStreetNm" runat="server"  TabIndex="14"
               
               
               
                style="z-index: 1; left: 587px; top: 352px; position: absolute; height: 24px;"></asp:TextBox>
            <asp:TextBox ID="txtPrmntCity" runat="server" TabIndex="15"
               
               
                style="z-index: 1; left: 234px; top: 392px; position: absolute; height: 24px;"></asp:TextBox>
            <asp:TextBox ID="txtPrmntHouseNo" runat="server"  TabIndex="13"
               
               
                style="z-index: 1; left: 234px; top: 352px; position: absolute; height: 24px;"></asp:TextBox>
            <asp:Label ID="Label28" runat="server" Font-Bold="True"
                style="z-index: 1; left: 411px; top: 246px; position: absolute; height: 23px; width: 148px"
                Text="DISTRICT"></asp:Label>
            <asp:Label ID="Label27" runat="server" Font-Bold="True"
                style="z-index: 1; left: 34px; top: 393px; position: absolute; height: 23px; width: 148px"
                Text="CITY"></asp:Label>
            <asp:Label ID="Label26" runat="server" Font-Bold="True"
                style="z-index: 1; left: 33px; top: 285px; position: absolute; height: 23px; width: 148px; margin-top: 0px;"
                Text="STATE"></asp:Label>
            <asp:Label ID="Label25" runat="server" Font-Bold="True"
                style="z-index: 1; left: 414px; top: 355px; position: absolute; height: 23px; width: 148px"
                Text="STREET NAME"></asp:Label>
            <asp:Label ID="Label24" runat="server" Font-Bold="True"
                style="z-index: 1; left: 34px; top: 212px; position: absolute; height: 23px; width: 148px"
                Text="HOUSE NUMBER"></asp:Label>
            <asp:Label ID="Label23" runat="server" Font-Bold="True" Font-Italic="True"
                Font-Size="Medium" Font-Underline="True"
                style="z-index: 1; left: 8px; top: 187px; position: absolute; height: 23px; width: 148px"
                Text="Present Address:"></asp:Label>
            <asp:TextBox ID="txtDistrict" runat="server" TabIndex="11"
               
               
                style="z-index: 1; left: 587px; top: 243px; position: absolute; height: 24px;"></asp:TextBox>
            <asp:TextBox ID="txtStreetNm" runat="server" TabIndex="9"
               
               
                style="z-index: 1; left: 588px; top: 205px; position: absolute; height: 24px;"></asp:TextBox>
            <asp:TextBox ID="txtHouseNo" runat="server" TabIndex="8"
               
               
                style="z-index: 1; left: 233px; top: 209px; position: absolute; height: 24px; width: 118px" ></asp:TextBox>
            <asp:Label ID="Label22" runat="server" Font-Bold="True"
                style="z-index: 1; left: 414px; top: 393px; position: absolute; height: 23px; width: 148px"
                Text="DISTRICT"></asp:Label>
            <asp:Label ID="Label21" runat="server" Font-Bold="True"
                style="z-index: 1; left: 411px; top: 208px; position: absolute; height: 23px; width: 148px"
                Text="STREET NAME"></asp:Label>
            <asp:Label ID="Label20" runat="server" Font-Bold="True"
                style="z-index: 1; left: 34px; top: 248px; position: absolute; height: 23px; width: 148px"
                Text="CITY"></asp:Label>
            <asp:TextBox ID="txtMotherNm" runat="server" TabIndex ="7"
               
               
                style="z-index: 1; left: 588px; top: 146px; position: absolute; height: 24px; width: 152px;"></asp:TextBox>
            <asp:TextBox ID="txtFatherNm" runat="server" TabIndex ="6"
               
                style="z-index: 1; left: 232px; top: 145px; position: absolute; height: 24px; width: 154px"></asp:TextBox>
            <asp:Label ID="Label19" runat="server" Font-Bold="True"
                style="z-index: 1; left: 28px; top: 147px; position: absolute; height: 23px; width: 148px"
                Text="FATHER NAME"></asp:Label>
            <asp:Label ID="Label18" runat="server" Font-Bold="True" Font-Italic="True"
                Font-Size="Medium" Font-Underline="True"
                style="z-index: 1; left: 9px; top: 327px; position: absolute; height: 23px; width: 148px"
                Text="Permanant Address:"></asp:Label>
            <asp:Label ID="Label17" runat="server" Font-Bold="True"
                style="z-index: 1; left: 33px; top: 355px; position: absolute; height: 23px; width: 148px"
                Text="HOUSE NUMBER"></asp:Label>
            <asp:DropDownList ID="ddMrMrs" runat="server" TabIndex="3"
               
                style="z-index: 1; left: 233px; top: 72px; position: absolute; height: 24px;" Font-Bold="True"
                >
                <asp:ListItem>Select</asp:ListItem>
                <asp:ListItem>Mr</asp:ListItem>
                <asp:ListItem>Mrs</asp:ListItem>
                <asp:ListItem>M/s</asp:ListItem>
            </asp:DropDownList>
            <asp:Label ID="Label15" runat="server" Font-Bold="True"
                style="z-index: 1; left: 33px; top: 654px; position: absolute; height: 23px; width: 148px; margin-top: 0px;"
                Text="DOMAIN NAME"></asp:Label>
            <asp:ImageButton ID="ImageButton1" runat="server" TabIndex="5"
                ImageUrl="~/calendar_icon.png"
               
               
                style="z-index: 1; left: 368px; top: 110px; position: absolute; height: 20px; width: 24px" />
            <asp:TextBox ID="txtPn" runat="server" Font-Size="12pt" MaxLength="10" TabIndex="19"
               
               
               
                style="z-index: 1; left: 235px; top: 536px; position: absolute; height: 24px; width: 152px;"></asp:TextBox>
            <asp:Label ID="Label11" runat="server" Font-Bold="True" Font-Italic="True"
                Font-Size="Medium"
                style="z-index: 1; left: 7px; top: 7px; position: absolute; height: 23px; width: 236px"
                Text="Enter Your Details Here..."></asp:Label>
            <asp:DropDownList ID="ddGdr" runat="server" TabIndex ="4"
               
               
                style="z-index: 1; left: 588px; top: 70px; position: absolute; height: 24px; width: 80px;">
                <asp:ListItem>Select</asp:ListItem>
                <asp:ListItem>Male</asp:ListItem>
                <asp:ListItem>Female</asp:ListItem>
            </asp:DropDownList>
            <asp:Label ID="Label12" runat="server" Font-Bold="True"
                style="z-index: 1; left: 32px; top: 539px; position: absolute; height: 23px; width: 148px; margin-top: 0px;"
                Text="PHONE NUMBER"></asp:Label>
            <asp:DropDownList ID="ddSt" runat="server"  TabIndex="12"
               
               
                style="z-index: 1; left: 234px; top: 285px; position: absolute; height: 13px; width: 137px">
                <asp:ListItem>Select</asp:ListItem>
                <asp:ListItem>Andhra Pradesh</asp:ListItem>
                <asp:ListItem>Karnataka</asp:ListItem>
                <asp:ListItem Value="0">Other</asp:ListItem>
            </asp:DropDownList>
            <asp:TextBox ID="txtSt" runat="server"
               
               
                style="z-index: 1; left: 411px; top: 284px; position: absolute; height: 24px; width: 156px"></asp:TextBox>
            <asp:Button ID="btnSignUp" runat="server" Font-Bold="True" TabIndex="24"
                style="z-index: 1; left: 298px; top: 792px; position: absolute; width: 74px;"
                Text="SIGN UP" />
            <asp:TextBox ID="txtVsno" runat="server" MaxLength="10"
               
                style="z-index: 1; left: 585px; top: 494px; position: absolute; height: 24px; width: 146px"></asp:TextBox>
            <asp:Label ID="Label13" runat="server" Font-Bold="True"
                style="z-index: 1; left: 415px; top: 497px; position: absolute; height: 23px; width: 148px; margin-top: 0px;"
                Text="VISA NUMBER"></asp:Label>
            <asp:DropDownList ID="ddCntry" runat="server" TabIndex="18"
               
                style="z-index: 1; left: 235px; top: 497px; position: absolute; height: 19px; width: 162px">
                <asp:ListItem>Select</asp:ListItem>
                <asp:ListItem Value="1">Australia</asp:ListItem>
                <asp:ListItem>China</asp:ListItem>
                <asp:ListItem Value="0">India</asp:ListItem>
                <asp:ListItem>USA</asp:ListItem>
            </asp:DropDownList>
            <asp:Label ID="Label14" runat="server" Font-Bold="True"
                style="z-index: 1; left: 32px; top: 498px; position: absolute; height: 23px; width: 148px; margin-top: 0px;"
                Text="COUNTRY"></asp:Label>
            <asp:Button ID="BtnClear" runat="server" Font-Bold="True" TabIndex="25"
                style="z-index: 1; left: 426px; top: 791px; position: absolute; height: 26px; width: 112px"
                Text="CLEAR ALL" />
            <asp:TextBox ID="txtOtherEmlDomain" runat="server"
               
                style="z-index: 1; left: 235px; top: 653px; position: absolute; height: 24px; width: 152px"></asp:TextBox>
            <asp:Label ID="Label16" runat="server" Font-Bold="True"
                style="z-index: 1; left: 32px; top: 616px; position: absolute; height: 23px; width: 148px; margin-top: 0px;"
                Text="EMAIL DOMAIN"></asp:Label>
            <asp:DropDownList ID="ddEmailDomain" runat="server" TabIndex="21"
               
                style="z-index: 1; left: 235px; top: 614px; position: absolute; height: 24px;">
                <asp:ListItem>Select</asp:ListItem>
                <asp:ListItem>@gmail.com</asp:ListItem>
                <asp:ListItem>@yahoo.com</asp:ListItem>
                <asp:ListItem>@intense.in</asp:ListItem>
                <asp:ListItem>@hotmail.com</asp:ListItem>
                <asp:ListItem>@outlook.com</asp:ListItem>
                <asp:ListItem>Other</asp:ListItem>
            </asp:DropDownList>
            <asp:TextBox ID="txtCity" runat="server" TabIndex="10"
               
               
                style="z-index: 1; left: 233px; top: 246px; position: absolute; height: 24px;"></asp:TextBox>
         
            <asp:Button ID="LoadBtn" runat="server" Font-Bold="True"
                style="z-index: 1; left: 578px; top: 790px; position: absolute; width: 68px"
                Text="LOAD" />
         
           
         
        </asp:Panel>
   
        <asp:Label ID="Label6" runat="server" Font-Bold="True" Font-Size="17pt"
            style="z-index: 1; left: 353px; top: 25px; position: absolute; height: 23px; width: 181px"
            Text="REGISTRATION"></asp:Label>
   
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
   
        <br />
        <br />
   
    </div>

    <asp:HiddenField ID="hf2" runat="server" />
    </form>
    <div id="dialog-confirm"></div>


Jquery code in Aspx page

<script type="text/javascript">
    $(document).ready(function () {
        $("#btnSignUp").click(function (e) {

            var tFirstName = $("#txtFn").val();
            var tLastName = $("#txtLn").val();

            var dob = $("#txtDob").val();
            var tGender = $("#ddGdr").val();
            var tMrMrs = $("#ddMrMrs").val();

            var tFatherName = $("#txtFatherNm").val();
            var tMotherName = $("#txtMotherNm").val();

            var tHiddenValue = $("#hf1").val();
            //Address
            var tHouseNo = $("#txtHouseNo").val();
            var tStreetNm = $("#txtStreetNm").val();
            var tCity = $("#txtCity").val();
            var tDistrict = $("#txtDistrict").val();
            var tState = $("#ddSt").val();
            var tOtherState = $("#txtSt").val();

            //PermanantAddress
            var tPrmntHouseNo = $("#txtPrmntHouseNo").val();
            var tPrmntStreetNm = $("#txtPrmntStreetNm").val();
            var tPrmntCity = $("#txtPrmntCity").val();
            var tPrmntDistrict = $("#txtPrmntDistrict").val();
            var tPrmntState = $("#ddPrmntState").val();
            var tPrmntOtherState = $("#txtPrmntOtherSt").val();

            var tCountry = $("#ddCntry").val();
            var tVisaNo = $("#txtVsno").val();

            var tPhoneNuumber = $("#txtPn").val();

            var tEmailID = $("#txtEid").val();
            var tEmailDomain = $("#ddEmailDomain").val();
            var tOtherEmlDomain = $("#txtOtherEmlDomain").val();

            var tPassword = $("#txtPwd").val();
            var tConformPassword = $("#txtCnPwd").val();

            var emptyField = "";
            var invalid = "\n";
            var flag = 0;
            var flag2 = 0;
            if (tEmailID == "" && tPhoneNuumber == "" && tConformPassword == "" && tPassword == ""
            && tFatherName == "" && tMotherName == "" && tFirstName == "" && tLastName == "" && dob == ""
             && tCity == "" && tHouseNo == "" && tDistrict == "" && tStreetNm == ""
             && tPrmntHouseNo == "" && tPrmntStreetNm == "" && tPrmntCity == "" && tPrmntDistrict == "") {              
                if (tState == "Select"
                 && tPrmntState == "Select"
                 && tMrMrs == "Select"
                 && tGender == "Select"
                 && tEmailDomain == "Select"
                 && tCountry == "Select") {
                    alert("Please, Enter the details. All fields are manditory!");
                    $("#txtFn").focus();
                    e.preventDefault();
                }
            }

            else {
           
                if (tFirstName == "") {
                    emptyField = emptyField + " FIRST NAME is MANDITORY " + "\n";
                    flag++;
                }
                else if (/^[a-zA-Z]*$/.test(tFirstName) == false) {
                   
                    invalid = invalid + " FIRST NAME is invalid " + "\n";
                    flag2++;
                }
                if (tLastName == "") {
                    emptyField = emptyField + " LAST NAME is MANDITORY " + "\n";
                    flag++;
                }
                else if (/^[a-zA-Z]*$/.test(tLastName) == false) {
                   
                    invalid = invalid + " LAST NAME is invalid" + "\n";
                    flag2++;

                }
                if (tFatherName == "") {                  
                    emptyField = emptyField + " FATHER NAME is MANDITORY " + "\n";
                    flag++;
                }
                else if (/^[a-zA-Z]*$/.test(tFatherName) == false) {
                    invalid = invalid + " FATHER NAME is invalid " + "\n";
                    flag2++;
                }
                if (tMotherName == "") {
                    //alert("Enter your last name!");
                    emptyField = emptyField + " MOTHER NAME is MANDITORY " + "\n";
                    flag++;
                }
                else if (/^[a-zA-Z]*$/.test(tMotherName) == false) {
                 
                    invalid = invalid + " MOTHER NAME is invalid" + "\n";
                    flag2++;

                }
                if (dob == "") {
                    emptyField = emptyField + " DATE OF BIRTH is MANDITORY " + "\n";
                    flag++;
                }
                if (tGender == "Select") {
                    emptyField = emptyField + " GENDER is MANDITORY " + "\n";
                    flag++;
                }
                if (tMrMrs == "Select") {
                    emptyField = emptyField + " MRMRS is MANDITORY " + "\n";
                    flag++;
                   
                }
                if (tHouseNo == "") {
                    emptyField = emptyField + " HOUSE NUMBER is MANDITORY " + "\n";
                    flag++;
                }
                if (tStreetNm == "") {
                    emptyField = emptyField + " STREET NAME is MANDITORY " + "\n";
                    flag++;
                   
                }
                else if (/^[a-zA-Z]*$/.test(tStreetNm) == false) {
                   
                    invalid = invalid + " STREET NAME is invalid" + "\n";
                    flag2++;
                }
                if (tCity == "") {
                    emptyField = emptyField + " CITY is MANDITORY " + "\n";
                    flag++;
                   
                }
                else if (/^[a-zA-Z]*$/.test(tCity) == false) {
                   
                    invalid = invalid + " CITY is invalid" + "\n";
                    flag2++;
                }
                if (tDistrict == "") {
                    emptyField = emptyField + " DISTRICT is MANDITORY " + "\n";
                    flag++;
                 
                }
                else if (/^[a-zA-Z]*$/.test(tDistrict) == false) {
                   
                    invalid = invalid + " DISTRICT is invalid" + "\n";
                    flag2++;
                }


                if (tState == "Select") {
                    emptyField = emptyField + " STATE is MANDITORY " + "\n";
                    flag++;
                   
                }
                else if (tState == 0 && tOtherState == "") {
                    emptyField = emptyField + " STATE is MANDITORY " + "\n";
                    flag++;
                }
                else if (/^[a-zA-Z]*$/.test(tOtherState) == false) {

                    invalid = invalid + " STATE is invalid" + "\n";
                    flag2++;
                }

                if (tPrmntHouseNo == "") {
                    emptyField = emptyField + " HOUSE NUMBER (Permanant) is MANDITORY " + "\n";
                    flag++;

                }
                if (tPrmntStreetNm == "") {
                    emptyField = emptyField + " STREET NAME (Permanant) is MANDITORY " + "\n";
                    flag++;

                }
                else if (/^[a-zA-Z]*$/.test(tPrmntStreetNm) == false) {

                    invalid = invalid + " STREET NAME (Permanant) is invalid" + "\n";
                    flag2++;
                }
                if (tPrmntCity == "") {
                    emptyField = emptyField + " CITY (Permanant) is MANDITORY " + "\n";
                    flag++;

                }
                else if (/^[a-zA-Z]*$/.test(tPrmntCity) == false) {

                    invalid = invalid + " CITY (Permanant) is invalid" + "\n";
                    flag2++;
                }


                if (tPrmntDistrict == "") {
                    emptyField = emptyField + " DISTRICT (Permanant) is MANDITORY " + "\n";
                    flag++;

                }
                else if (/^[a-zA-Z]*$/.test(tPrmntDistrict) == false) {

                    invalid = invalid + " DISTRICT (Permanant) is invalid" + "\n";
                    flag2++;

                }

                if (tPrmntState == "Select") {
                    emptyField = emptyField + " STATE (Permanant) is MANDITORY " + "\n";
                    flag++;
                 
                }
                else if (tPrmntState == 0 && tPrmntOtherState == "") {
                    emptyField = emptyField + " STATE (Permanant) is MANDITORY " + "\n";
                    flag++;
                }
                else if (/^[a-zA-Z]*$/.test(tPrmntOtherState) == false) {

                    invalid = invalid + "Permanant STATE is invalid" + "\n";
                    flag2++;
                }

                if (tPhoneNuumber == "") {
                    emptyField = emptyField + " PHONE NUMBER is MANDITORY " + "\n";
                    flag++;
                 
                }
                else if (/^([0-9]{10})/.test(tPhoneNuumber) == false) {
                   
                    invalid = invalid + " PHONE NUMBER is invalid" + "\n";
                    flag2++;
                }
                if (tEmailID == "") {
                    emptyField = emptyField + " EMAIL ID is MANDITORY " + "\n";
                    flag++;
                   
                }
                else if (/^[a-zA-Z]*$/.test(tEmailID) == false) {
                   
                    invalid = invalid + " EMAIL ID is invalid" + "\n";
                    flag2++;
                }
                if (tEmailDomain == "Select") {
                    emptyField = emptyField + " EMAIL DOMAIN is MANDITORY " + "\n";
                    flag++;

                }
                else if (tEmailDomain == 0 && tOtherEmlDomain == "") {
                    emptyField = emptyField + " EMAIL DOMAIN is MANDITORY " + "\n";
                    flag++;
                }
                else if (!IsEmail(tOtherEmlDomain)) {

                    invalid = invalid + " EMAIL DOMAIN is invalid" + "\n";
                    flag2++;
                }
                if (tPassword == "") {
                    emptyField = emptyField + " PASSWORD is MANDITORY " + "\n";
                    flag++;
                   
                }
                if (tConformPassword == "") {

                    emptyField = emptyField + " CONFORM PASSWORD is MANDITORY " + "\n";
                    flag++;
                   
                }
                else if (tConformPassword != tPassword) {
                   
                    invalid = invalid + " CONFORM PASSWORD should Match with Password. ";
                    flag2++;
                }
                if (tCountry == "Select") {
                    emptyField = emptyField + " COUNTRY is MANDITORY " + "\n";
                    flag++;
                   
                }
                else if (tCountry != 0 && tVisaNo == "") {
                    emptyField = emptyField + " VISA NUMBER is MANDITORY " + "\n";
                    flag++;
                }
                else if (/^([0-9])/.test(tVisaNo) == false) {
                    invalid = invalid + " VISA NUMBER is invalid" + "\n";
                    flag2++;
                }

                if (flag != 0 && flag2 != 0) {
                    alert(emptyField + "  " + "\n" + invalid);
                    e.preventDefault();

                }
                else if (flag != 0) {
                    alert("\n" + emptyField);
                    e.preventDefault();
                }
                else if (flag2 != 0) {
                    alert("\n" + invalid);
                    e.preventDefault();
                }

                else {
                    alert("Hai " + $("#txtFn").val() + ", You are successfully Registered!! " + $("#hf1").val());



                    $("#txtFn").focus();
                    e.preventDefault();
                }  
                }          
     
      });
   
        function IsEmail(email) {
            var regex = /\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
            return regex.test(email);
        }
       
          });
          $(function () {
              $("#LoadBtn").click(function (e) { $.ajax({
                type: 'GET',
                url: 'XMLFile.xml',
                dataType: 'xml',
                success:
                        function (xml) {
                            $(xml).find('Details').each(function () {

                                $("#txtFn").val($(this).find('FirstName').text());
                                $("#txtLn").val($(this).find('LastName').text());                              
                                $("#ddGdr option:selected").text($(this).find('Gender').text());
                                $("#ddMrMrs option:selected").text($(this).find('MrMrs').text());
                                $("#txtDob").val($(this).find('DOB').text());
                                $("#txtFatherNm").val($(this).find('FatherName').text());
                                $("#txtMotherNm").val($(this).find('MotherName').text());
                                $("#txtHouseNo").val($(this).find('HouseNo').text());
                                $("#txtStreetNm").val($(this).find('StreetName').text());
                                $("#txtCity").val($(this).find('City').text());
                                $("#txtDistrict").val($(this).find('District').text());
                                $("#ddSt option:selected").val($(this).find('State').text());
                                if ($("#txtSt").text != "") {
                                    $("#txtSt").show();
                                    $("#txtSt").val($(this).find('OtherState').text())
                                }
                                else {

                                }
                                $("#txtPrmntHouseNo").val($(this).find('PermanantHouseNo').text());
                                $("#txtPrmntStreetNm").val($(this).find('PermanantStreetName').text());
                                $("#txtPrmntCity").val($(this).find('PermanantCity').text());
                                $("#txtPrmntDistrict").val($(this).find('PermanantDistrict').text());
                                $("#ddPrmntState option:selected").text($(this).find('PermanantState').text());
                                if ($("#txtPrmntOtherSt").text != "") {
                                    $("#txtPrmntOtherSt").show();
                                    $("#txtPrmntOtherSt").val($(this).find('PermanantOtherState').text())
                                }
                                $("#ddCntry option:selected").val($(this).find('Country').text());
                                $("#txtVsno").val($(this).find('VisaNumber').text());
                                $("#txtEid").val($(this).find('Email').text());
                                $("#ddEmailDomain option:selected").text($(this).find('EmailDomain').text());
                                if ($("#txtOtherEmlDomain").text != "") {
                                    $("#txtOtherEmlDomain").show();
                                    $("#txtOtherEmlDomain").val($(this).find('OtherEmailDomain').text())
                                }
                                else
                                $("#txtOtherEmlDomain").val($(this).find('EmailDomain').text());
                                $("#txtPn").val($(this).find('PhoneNumber').text());
                             });
                        }
            });
            return false;
               
          });
      $(function () {
        $('#BtnClear').click(function (f) {
               
                $("#txtFn").val('');
                $("#txtLn").val('');

                $("#txtDob").val('');
                $("#ddGdr").val("Select");
                $("#ddMrMrs").val("Select");

                $("#txtFatherNm").val('');
                $("#txtMotherNm").val('');

         
            //Address
                $("#txtHouseNo").val('');
                $("#txtStreetNm").val('');
                $("#txtCity").val('');
                $("#txtDistrict").val('');
                $("#ddSt").val("Select");
                $("#txtSt").val('');

            //PermanantAddress
            $("#txtPrmntHouseNo").val('');
            $("#txtPrmntStreetNm").val('');
            $("#txtPrmntCity").val('');
            $("#txtPrmntDistrict").val('');
            $("#ddPrmntState").val("Select");
            $("#txtPrmntOtherSt").val('');

            $("#ddCntry").val("Select");
            $("#txtVsno").val('');

            $("#txtPn").val('');

            $("#txtEid").val('');
            $("#ddEmailDomain").val("Select");
            $("#txtOtherEmlDomain").val('');

            $("#txtPwd").val('');
            $("#txtCnPwd").val('');

            $("#txtSt").hide();
            $("#txtPrmntOtherSt").hide();

            $('#txtVsno').prop('disabled', true);
            $('#txtOtherEmlDomain').prop('disabled', true);

            $("#txtFn").focus();
            f.preventDefault();
        });
    });

         $(function () {
            $("#txtPrmntOtherSt").hide();

            $('#ddPrmntState').change(function (o) {
                if ($(this).val() == 0) {
                    $("#txtPrmntOtherSt").show();
                    $("#txtPrmntOtherSt").focus();
                    o.preventDefault();
                }
                else
                    $("#txtSt").hide();


            })
        });

        $(function () {
            $("#txtSt").hide();

            $('#ddSt').change(function (s) {
                if ($(this).val() == 0) {
                    $("#txtSt").show();
                    $("#txtSt").focus();
                    s.preventDefault();
                }
                else
                    $("#txtSt").hide();


            })
        });

        $(function () {
            $('#txtVsno').prop('disabled', true);
            $('#ddCntry').change(function (v) {
                if ($(this).find('option:selected').text() == 'India' || $(this).find('option:selected').text() == 'Select') {
                    $('#txtVsno').prop('disabled', true);
                } else {
                    $("#txtVsno").val('');
                    $('#txtVsno').prop('disabled', false)
                    $("#txtVsno").focus();
                    v.preventDefault();
                }
            })
        });

        $(function () {
            $('#ddGdr').prop('disabled', false);
            $('#ddMrMrs').change(function () {
                if ($(this).find('option:selected').text() == 'Mr') {
                    $("#ddGdr").val("Male");
                    $('#ddGdr').prop('disabled', true);
                }
                else if ($(this).find('option:selected').text() == 'Select') {
                    $('#ddGdr').prop('disabled', false)
                }
                else
                    $("#ddGdr").val("Female");
                $('#ddGdr').prop('disabled', true);
            })
        });

        $(function () {
            $('#txtOtherEmlDomain').prop('disabled', true);
            $('#ddEmailDomain').change(function (d) {
                if ($(this).find('option:selected').text() == 'Other') {
                    $("#txtOtherEmlDomain").val('');
                    $('#txtOtherEmlDomain').prop('disabled', false);
                    $("#txtOtherEmlDomain").focus();
                    d.preventDefault();
                } else {
                    var selctedDomNm = $("#ddEmailDomain").val();
                    $("#txtOtherEmlDomain").val(selctedDomNm);
                    $('#txtOtherEmlDomain').prop('disabled', true)
                }
            })
        });
       
        $(function () {

            $('#txtPrmntHouseNo').focus(function () {

                if (confirm('Are you Sure?') == true) {

                    var tHouseNo = $("#txtHouseNo").val();
                    var tStreetNm = $("#txtStreetNm").val();
                    var tCity = $("#txtCity").val();
                    var tDistrict = $("#txtDistrict").val();
                    var tState = $("#ddSt").val();
                    var tOtherState = $("#txtSt").val();

                    //PermanantAddress
                    $("#txtPrmntHouseNo").val(tHouseNo);
                    $("#txtPrmntStreetNm").val(tStreetNm);
                    $("#txtPrmntCity").val(tCity);
                    $("#txtPrmntDistrict").val(tDistrict);
                    $("#ddPrmntState").val(tState);
                    $("#txtPrmntOtherSt").val(tOtherState);


                    $('#txtPrmntHouseNo').prop('disabled', true);
                    $('#txtPrmntStreetNm').prop('disabled', true);
                    $('#txtPrmntCity').prop('disabled', true);
                    $('#txtPrmntDistrict').prop('disabled', true);
                    $('#ddPrmntState').prop('disabled', true);
                    if ($('#ddSt').find('option:selected').text() == 'Other') {
                        $("#txtPrmntOtherSt").show();
                        $('#txtPrmntOtherSt').prop('disabled', true)
                    }
                }

            });
        });


        $(function () {
            $('#txtHouseNo').bind('input propertychange', function () {

                $('#txtPrmntHouseNo').prop('disabled', false);
                $('#txtPrmntStreetNm').prop('disabled', false);
                $('#txtPrmntCity').prop('disabled', false);
                $('#txtPrmntDistrict').prop('disabled', false);
                $('#ddPrmntState').prop('disabled', false);
                if ($('#ddSt').find('option:selected').text() == 'Other') {
                    $("#txtPrmntOtherSt").show();
                    $('#txtPrmntOtherSt').prop('disabled', false)
                }
            });
        });
    });

</script>

Code under Page_load


 protected void Page_Load(object sender, EventArgs e)
        {          
            txtDob_CalendarExtender.EndDate=DateTime.Now;
            txtDob_CalendarExtender.Format = "dd/MM/yyyy";

        }

Coder Under button click

 protected void SaveBtn_Click(object sender, EventArgs e)
        {

            try
            {
                txtDob.ReadOnly = false;
                ddGdr.Enabled = true;
                string FirstName = txtFn.Text;
                string LastName = txtLn.Text;
                string MrMrs = ddMrMrs.Text;
                string Gender = ddGdr.Text;
                string Dob = txtDob.Text;
                string FatherName = txtFatherNm.Text;
                string MotherName = txtMotherNm.Text;
                string HouseNo = txtHouseNo.Text;
                string StreetNm = txtStreetNm.Text;
                string City = txtCity.Text;
                string District = txtDistrict.Text;
                string State = ddSt.Text;
                 string otherState = null;
                if (State == "Other")
                {

                     otherState = txtSt.Text;

                }
               
                string ptHouseNo = txtPrmntHouseNo.Text;
                string ptStreetNm = txtPrmntStreetNm.Text;
                string ptCity = txtPrmntCity.Text;
                string ptDistrict = txtPrmntDistrict.Text;
                string ptState = ddPrmntState.Text;
                string ptotherState =null;
                if (ptState == "Other")
                {
                    ptotherState = txtPrmntOtherSt.Text;
                }
                string country = ddCntry.Text;
                string visaNo = null;
                if (country != "India" && country != "Select")
                {
                    visaNo = txtVsno.Text;
                }
               
                string phoneNo = txtPn.Text;
                string emailid = txtEid.Text;
                string emailDomain = ddEmailDomain.Text;
                 string otherdomain=null;
                if (emailDomain == "Other")
                {
                    otherdomain = txtOtherEmlDomain.Text;
                }

                string password = txtPwd.Text;

                var x = new XDocument(
                    new XElement("Details",
                        new XElement("FirstName", FirstName),
                        new XElement("LastName", LastName),
                        new XElement("MrMrs", MrMrs),
                        new XElement("Gender", Gender),
                        new XElement("DOB", Dob),
                        new XElement("FatherName", FatherName),
                        new XElement("MotherName", MotherName),
                        new XElement("HouseNo", HouseNo),
                        new XElement("StreetName", StreetNm),
                        new XElement("District", District),
                        new XElement("City", City),
                        new XElement("State", State),
                        new XElement("OtherState",otherState),
                        new XElement("PermanantHouseNo", ptHouseNo),
                        new XElement("PermanantStreetName", ptStreetNm),
                        new XElement("PermanantCity", ptCity),
                        new XElement("PermanantDistrict", ptDistrict),
                        new XElement("PermanantState", ptState),
                        new XElement("PermanantOtherState",ptotherState),
                        new XElement("Country", country),
                        new XElement("VisaNumber", visaNo),
                        new XElement("PhoneNumber", phoneNo),
                        new XElement("EmailID", emailid),
                        new XElement("EmailDomain", emailDomain),
                        new XElement("OtherEmailDomain",otherdomain),
                        new XElement("Password", password)
                        )
                );

                x.Save(@"C:\Users\umamaheswar.b\Desktop\RegistrationJquery\RegistrationJquery\RegistrationJquery\XMLFile.xml");

            }
            catch (Exception)
            {
                throw;
            }
        }
             

    }

XML File

<?xml version="1.0" encoding="utf-8"?>
<Details>
  <FirstName>Umamaheswar </FirstName>
  <LastName>Rao</LastName>
  <MrMrs>Mr</MrMrs>
  <Gender>M</Gender>
  <DOB></DOB>
  <FatherName>Father name</FatherName>
  <MotherName>Mother name</MotherName>
  <HouseNo>123</HouseNo>
  <StreetName>housestreet</StreetName>
  <District>Hyderabad</District>
  <City>Hyderabad</City>
  <State>Telangana</State>
  <OtherState />
  <PermanantHouseNo></PermanantHouseNo>
  <PermanantStreetName></PermanantStreetName>
  <PermanantCity></PermanantCity>
  <PermanantDistrict></PermanantDistrict>
  <PermanantState>Select</PermanantState>
  <PermanantOtherState />
  <Country>1</Country>
  <VisaNumber>54646655465</VisaNumber>
  <PhoneNumber>66666665665</PhoneNumber>
  <EmailID>umamaheswarraob</EmailID>
  <EmailDomain>@gmail.com</EmailDomain>
  <OtherEmailDomain />
  <Password>****</Password>
</Details>