Click here to Skip to main content
16,012,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to apply simply jquery validation in asp.net using asp.net controls...my asp.net form is this please take me solution fast.....





XML
<%@ Page Title="" Language="C#" MasterPageFile="~/Register/Presentation/MasterPage.master" AutoEventWireup="true" CodeFile="RegisterUser.aspx.cs" Inherits="Register_Presentation_RegisterUser" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">


<div class="login_field_bg" id="registerDiv">
              <div class="center_page" >
                <h1><samp>Sign Up</samp></h1>
                <div class="login_text"><span>First Name: </span>
                    <asp:TextBox ID="First_Name_text" runat="server" CssClass="input_text " ></asp:TextBox>
                 <%-- <input type="text" name="" value="" id="First_Name_text" class="input_text validate[required]"/>--%>
                </div>
                <div class="login_text"><span>Last Name:</span>
                    <asp:TextBox ID="Last_name_text" runat="server"  CssClass="input_text "></asp:TextBox>
                  <%--<input type="text" name="" id="Last_name_text" value=""  class="input_text validate[required]"/>--%>
                </div>
                <div class="login_text"><span>Email Id:</span>
                    <asp:TextBox ID="Email_id_text" runat="server" CssClass="input_text"></asp:TextBox>
                  <%--<input type="text" name="" value="" id="Email_id_text" class="input_text validate[required,custom[email]" />--%>
                </div>
                <div class="login_text"><span>Password:</span>
                    <asp:TextBox ID="Password_text" runat="server"
                        CssClass="input_text " TextMode="Password"></asp:TextBox>
                  <%--<input type="password" name="" value="" id="Password_text" class="input_text validate[required]"/>--%>
                </div>
                <div class="login_text"><span>Confirm Password:</span>
                    <asp:TextBox ID="Confirm_password_text" runat="server" CssClass="input_text" TextMode="Password"></asp:TextBox>
                <%--  <input type="password" name="" value="" id="Confirm_password_text" class="input_text validate[required]" />--%>
               <%-- <asp:CompareValidator ID="CompareValidator1" runat="server"
                        ErrorMessage="password don't match" ControlToCompare="Password_text"
                        ControlToValidate="Confirm_password_text" Font-Bold="True" ForeColor="Red"></asp:CompareValidator>--%>
                </div>
                <div class="login_text">
                  <div class="remember_me">
                    <input type="checkbox" name="" value="" class="checkbox" />
                    <a href="#">Send me updates</a> </div>
                  <div class="account_login">

                      <asp:Button ID="Register_button" runat="server" CssClass="login_account"
                          Text="Register" onclick="Register_button_Click"/>
                    <%--<input type="submit" id="Register_button" name=""  value="Register" class="login_account"/>--%>
                  </div>
                </div>
              </div>
            </div>
</asp:Content>
Posted

Hi friend,
first download JQuery file from link http://code.jquery.com/jquery-1.8.3.min.js[^] and add folder inside your project by the name of 'js' and now add downloaded JQuery file inside the 'js' folder then do as i am doing below where i am only checking the 'Firt Name' textbox is Empty or not if Empty then i am showing alert message.
for validation copy & paste below code inside your ContentPlaceHolder1.

XML
<script src="js/jquery-1.8.3.min.js"></script>
   <script type="text/javascript">
       $(document).ready(function () {
           $("[Id$='Register_button']").click(function () {
               var First_Name_text = $("[Id$='First_Name_text']");
               if (First_Name_text.val()=='') {
                   alert("Please enter first name.")
                   return false;
               }
           });
       });
   </script>
 
Share this answer
 
Comments
Amrender Saini 2-Jul-13 7:45am    
thanks for help friend...
jquiry validation is very easy... it just gives a notification... i will post some code here....check it


C#
function ValidateControls()
       {
           if(document.getElementById("ctl00_MainContent_txtFirstName").value == "")
           {
               alert('Please Enter First Name');
               document.getElementById("ctl00_MainContent_txtFirstName").focus();
               return false;
           }
           if(document.getElementById("ctl00_MainContent_txtLastName").value == "")
           {
               alert('Please Enter Last Name');
               document.getElementById("ctl00_MainContent_txtLastName").focus();
               return false;
           }

}



the above code having two
validations
frst name and last name
if u enter the
firstname and click the submit button then it will show the alert box with contents of enter the last name... then only the submisstion should be performed...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900