asp.net - how to do the validation of content page using jquery -


hii master page

<%@ master language="c#" autoeventwireup="true" codefile="officeapps.master.cs" inherits="master1" %>  <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">   <head runat="server">   <meta http-equiv="content-type" content="text/html;charset=utf-8" />   <link rel="stylesheet" type="text/css" href="styles/jquery-ui-1.8.1.custom.css" />   <link rel="stylesheet" type="text/css" href="styles/ui.jqgrid.css" />   <link rel="stylesheet" type="text/css" href="styles/ui.multiselect.css" />    <script src="js/jquery.js" type="text/javascript"></script>   <script src="js/jquery-1.3.1.min.js" type="text/javascript"></script>   <script src="js/hoverintent.js" type="text/javascript"></script>   <link href="styles/masterstylesheet.css" rel="stylesheet" type="text/css" />   <title></title>   <asp:contentplaceholder id="head" runat="server">   </asp:contentplaceholder> </head>  <body>  <form id="form1" runat="server">   <div>     <table class="mastertable">         <tr>             <td class="masterheader">                 <asp:contentplaceholder id="contentplaceholder1" runat="server">                       <div class="logo">                         <asp:image id="image2" class="logo1" src="images/officeapps.png" runat="server" />                     </div>                     <div class="menubar">                         <asp:literal id="literal1" runat="server"></asp:literal>                     </div>                 </asp:contentplaceholder>             </td>         </tr>            <tr>             <td class="mastercontent">                  <asp:contentplaceholder id="contentplaceholder2" runat="server">                 </asp:contentplaceholder>                <div class="divbutpos">      <asp:button id="button1" runat="server" text="logout" onclick="button1_click" backcolor="#00ccff"         borderstyle="none" font-bold="true" font-names="verdana" font-underline="true"         forecolor="white" style="cursor: hand" />     <%-- <asp:imagebutton id="imagebutton1"  cssclass="divbutpos" onclick="button1_click" imageurl="~/images/signout.jpg" runat="server" />--%>    </div>              </td>         </tr>          <tr>              <td class="masterfooter">                 <asp:contentplaceholder id="contentplaceholder3" runat="server">                 </asp:contentplaceholder>             </td>         </tr>    </table> </div> 

the reason posted entire masterpage has multiple contentplaceholders in table format.....

my content page looks this

<%@ page title="" language="c#" masterpagefile="~/officeapps.master" autoeventwireup="true"     codefile="usersgrid.aspx.cs" inherits="usersgrid" %>  <asp:content id="content1" contentplaceholderid="head" runat="server"> </asp:content>  <asp:content id="content3" contentplaceholderid="contentplaceholder2" runat="server">  <div class = "scroll">      <div id="searchbox" title="searchbox" class="searchbox">         <div class="searchboxheader">             <h2 style="text-align: center; color: #2e6e9e;">                 search</h2>         </div>          <asp:label id="lbl_filterstatus" runat="server">status: </asp:label>  <asp:dropdownlist             id="dl_filterstatus" runat="server">             <asp:listitem value="1" selected="true">active</asp:listitem>             <asp:listitem value="0">inactive</asp:listitem>         </asp:dropdownlist>         <asp:label id="lbl_filteruname" runat="server">username: </asp:label><asp:textbox             id="tb_filteruname" runat="server"></asp:textbox>         <asp:label id="lbl_filtersname" runat="server">shortname: </asp:label><asp:textbox             id="tb_filtersname" runat="server"></asp:textbox>         <asp:imagebutton id="imagebutton1" runat="server" imageurl="images/search_icon.gif"             imagealign="absbottom" onclientclick="return searchuser();" />     </div>  <table id="usergrid"> </table>  <div id="pager1" style="text-align: center;"> </div>  </div>  <div class="divlblpos">         <asp:label cssclass="welcomelogo" id="label1" runat="server" text="welcome"></asp:label>         <asp:label id="label2" runat="server" cssclass="welcomelogo"></asp:label> </div> <asp:hiddenfield id="hf_selectedid" runat="server" />     <div id="dialog" title="userdetails" style="display: none;">      <table  cellspacing="5px" cellpadding="10px">         <tr>             <td>                 <asp:label id="lbl_usrnm" cssclass="popuptxt" runat="server" text="username"></asp:label>             </td>             <td>                 <asp:textbox id="tb_username" height="15px" font-size="13px" runat="server"></asp:textbox>             </td>           <td>                 <asp:label id="unameerror" runat="server" text=""></asp:label>             </td>          </tr>         <tr>             <td>                 <asp:label id="lbl_name" cssclass="popuptxt" runat="server" text="name"></asp:label>             </td>             <td>                 <asp:textbox id="tb_name" height="15px" font-size="13px" runat="server"></asp:textbox>             </td>         </tr>         <tr>             <td>                 <asp:label id="lbl_shortnm" cssclass="popuptxt" runat="server" text="shortname"></asp:label>             </td>             <td>                 <asp:textbox id="tb_sname" height="15px" font-size="13px" runat="server"></asp:textbox>             </td>         </tr>         <tr>             <td>                 <asp:label id="lbl_admin" cssclass="popuptxt" runat="server" text="isadmin"></asp:label>             </td>             <td>                 <asp:checkbox id="cb_admin" checked="false" runat="server" />             </td>         </tr>         <tr>             <td>                 <asp:label id="lbl_active" cssclass="popuptxt" runat="server" text="isactive"></asp:label>             </td>             <td>                 <asp:checkbox id="cb_active" checked="false" runat="server" />             </td>         </tr>         <tr>             <td>                 <asp:label id="lbl_email" cssclass="popuptxt" runat="server" text="email"></asp:label>             </td>             <td>                 <asp:textbox id="tb_email" height="15px" font-size="13px" runat="server"></asp:textbox>             </td>         </tr>         <tr>             <td>                 <asp:label id="lbl_phone" cssclass="popuptxt" runat="server" text="phone"></asp:label>             </td>             <td>                 <asp:textbox id="tb_phone" height="15px" font-size="13px" runat="server"></asp:textbox>             </td>         </tr>         <tr>             <td>                 <asp:label id="lbl_mob" cssclass="popuptxt" runat="server" text="mobile"></asp:label>             </td>             <td>                 <asp:textbox id="tb_mobile" height="15px" font-size="13px" runat="server"></asp:textbox>             </td>         </tr>         <tr>             <td>                 <asp:label id="lbl_depts" cssclass="popuptxt" runat="server" text="departments"></asp:label>             </td>             <td>                 <asp:listbox id="lb_departments" font-size="13px" datatextfield="departmentname"                     width="154px" datavaluefield="departmentid" runat="server" selectionmode="multiple">                 </asp:listbox>             </td>         </tr>         <tr>             <td>                 <asp:label id="lbl_app" cssclass="popuptxt" runat="server" text="applications"></asp:label>             </td>             <td>                 <asp:listbox id="lb_applications" datatextfield="applicationname" font-size="13px"                     width="154px" datavaluefield="applicationid" runat="server" selectionmode="multiple">                 </asp:listbox>             </td>         </tr>         <tr>             <td>                 <asp:label id="lbl_sup" cssclass="popuptxt" runat="server" text="supervisors"></asp:label>             </td>             <td>                 <asp:listbox id="lb_supervisor" datatextfield="username" font-size="13px" width="154px"                     datavaluefield="userid" runat="server" selectionmode="multiple"></asp:listbox>             </td>         </tr>         <tr>             <td>                 <asp:label id="lb_success" font-size="10px" runat="server" text=""></asp:label>             </td>             <td>                                     <asp:button id="button_edit" width="150px" runat="server" text="edit" onclientclick="return edituser();" />                                 </td>         </tr>     </table> </div> </asp:content> <asp:content id="content4" contentplaceholderid="contentplaceholder3" runat="server"> </asp:content> 

my problem when have validate using below code inside contentplaceholder validation not being done code is

<script type="text/javascript">        $.validator.addmethod("regex",function(value, element, regexp)              {                 var check = false;                 var re = new regexp(regexp);              return this.optional(element) || re.test(value);             },"<p style='color:red'>*please check input</p>");            $(document).ready(function() {             $("#aspnetform").validate({                 rules: {                     <%=tb_username.uniqueid %>: {                         minlength: 5,                         required: true,                      regex: "^[a-za-z0-9'.\\s\]{3,15}$"                       },                     <%=tb_name.uniqueid %>: {                         minlength: 5,                         required: true,                     regex: "^[a-za-z0-9'.\\s\]{3,15}$"                      },                     <%=tb_sname.uniqueid %>: {                         required: true,                     maxlength:4,                     regex: "^[a-za-z0-9'.\\s\]{1,4}$"                      },                     <%=tb_email.uniqueid %>: {                      required: true,                     regex:"^[a-za-z0-9._-]+@[a-za-z0-9.-]+\.[a-za-z]{2,4}$"                     },                     <%=tb_phone.uniqueid %>: {                         minlength: 8,                         maxlength: 8,                         required: true,                     regex:"^[0-9\s]{8}$"                     },                     <%=tb_mobile.uniqueid %>: {                         minlength: 10,                         maxlength:10,                         required: true,                         regex:"^[0-9\s]{10}$"                     }                 },                  messages: {                     <%=tb_username.uniqueid %>:{                          required: "please enter username",                          minlength: "user name must atleast of 5 characters"                      },                      <%=tb_name.uniqueid %>:{                          required: "please enter name",                          minlength: "name must atleast of 5 characters"                      },                      <%=tb_sname.uniqueid %>:{                          required: "please enter shortname",                        maxlength:"shortname cant exceed 4 characters"                     },                      <%=tb_email.uniqueid %>:{                          required: "please enter email",                       },                     <%=tb_phone.uniqueid %>:{                          required: "please enter phone",                        minlength:"phone number should have 8 digits",                       maxlength:"phone number should have 8 digits only"                     },                   <%=tb_mobile.uniqueid %>:{                          required: "please entermobile number",                          minlength: "mobile number should have 10 digits"                         maxlength:"mobile number should have 10 digits only"                     }                     }             });         });     </script> 

why not use asp.net validators, same thing you're trying do, plus server side validation!

  • regularexpressionvalidator(can used min , max length)
  • requiredfieldvalidator

server side validation must because javascript can disabled or modified user.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -