c# - page get refresh evenif usercontrol validation is false -


i have usercontrol in have written custom-validation checks whether entered data in textbox correct location or not.on button click click have checked (page.isvalid) bit,

even-if validation fails reload entire page in usercontrol added

the custom validation like;

   <asp:customvalidator id="customvalidator1"  runat="server" width="102px" style="margin-left:37px !important" onservervalidate="textvalidate" controltovalidate="txtlocationid" errormessage="incorrect location.">   </asp:customvalidator> 

in usercontrol.aspx.cs :->

protected void textvalidate(object source, servervalidateeventargs args)         {             string value = string.empty;             dbconfig.condatabase2.open();             sqlcommand cmdsqlcmd = new sqlcommand();             cmdsqlcmd.commandtype = commandtype.text;             string locid = args.value.tostring();             cmdsqlcmd.commandtext = "";             cmdsqlcmd.connection = dbconfig.condatabase2;              object ob = cmdsqlcmd.executescalar();             if (ob == null)             {                 args.isvalid = false;             }             else             {                 args.isvalid = true;             }         } 

on button click:

protected void gobutton_onclick(object sender, eventargs e) { if (page.isvalid) { code goes here... } }

in aspx page:

<%@ register src="usercontrol/usercontrolfilter.ascx" tagname="usercontrolfilter"     tagprefix="uc1" %> <html> <body>     <form id="form1" runat="server">     <ajaxtoolkit:toolkitscriptmanager id="toolkitscriptmanager1" runat="server">     </ajaxtoolkit:toolkitscriptmanager>     <asp:timer id="timer1" runat="server" ontick="timer1_tick" interval="300000">     </asp:timer>     <asp:updatepanel id="updatepanel1" updatemode="conditional" runat="server">                         <triggers>                             <asp:asyncpostbacktrigger controlid="timer1" eventname="tick" />                         </triggers>                         <contenttemplate>                           <div class="locadetail" id="bigtrends" style="border-radius:5px;width: 884px; z-index: 100; border-width: 1px;                                 margin: 10px; height: 398px !important; float: left; background-color: #fff !important;">                             </div>                         </contenttemplate>                     </asp:updatepanel> </form> </body> </html> 

kindly let me know if m going wrong somewhere

thanks

custom validation have 2 modes 1. client side , 2. server side. if using server side validation page post without check. , before page validation event, page load fired add client validation function. validate test. if data need check available on server use web service validate.

<script language="javascript"> function textvalidate(osrc, args){ // validation logic 

}

<asp:customvalidator id="customvalidator1" runat="server" width="102px" style="margin-left:37px !important" onservervalidate="textvalidate" controltovalidate="txtlocationid" errormessage="incorrect location." clientvalidationfunction="textvalidate" > </asp:customvalidator>


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -