c# - Client-Side validation with Telerik ASP.NET Ajax doesn't work -
i'm working telerik radcontrols asp.net ajax, , want create client side validation page. created usercontrol , followed this tutorial found on telerik site. unfortunatly doesn't work , have no idea i've done wrong. take @ code me , point me in right direction?
<%@ control language="c#" autoeventwireup="false" codebehind="manageaccountcontrol.ascx.cs" inherits="docl.webdoc.controls.account.manageaccountcontrol" %> <style type="text/css"> .btn { margin-top: 15px; } </style> <div id="createuser" style="margin: 10px 10px 10px 10px"> <telerik:radscriptmanager id="radscriptmanager1" runat="server"></telerik:radscriptmanager> <telerik:radskinmanager id="qsfskinmanager" runat="server" showchooser="true" /> <telerik:radformdecorator id="qsffromdecorator" runat="server" decoratedcontrols="all" enableroundedcorners="false" /> <telerik:radajaxpanel id="rappanel" runat="server" loadingpanelid="loadingpanel1"> <div onclick="validate()"> <table class="adminprops"> <tr> <td>email</td> <td> <telerik:radtextbox id="ctrlemail" runat="server"> </telerik:radtextbox></td> <td> <asp:panel id="pnlemail" runat="server" width="25px"> <asp:regularexpressionvalidator display="dynamic" id="regexemail" validationexpression="^[a-za-z][\w\.-]*[a-za-z0-9]@[a-za-z0-9][\w\.-]*[a-za-z0-9]\.[a-za-z][a-za-z\.]*[a-za-z]$" runat="server" controltovalidate="ctrlemail" errormessage="a valid email required!" enableclientscript="true">*</asp:regularexpressionvalidator> <asp:requiredfieldvalidator id="rfvemail" runat="server" validationgroup="group1" controltovalidate="ctrlemail" errormessage="email required" display="dynamic">*</asp:requiredfieldvalidator> </asp:panel> </td> </tr> <tr> <td>voornaam</td> <td> <telerik:radtextbox id="ctrlfirstname" runat="server"></telerik:radtextbox></td> <td> <asp:panel id="pnlfirstname" runat="server" width="25px"> <asp:requiredfieldvalidator id="rfvfirstname" runat="server" validationgroup="group1" controltovalidate="ctrlfirstname" errormessage="firstname required" display="dynamic" enableclientscript="true">*</asp:requiredfieldvalidator> </asp:panel> </td> </tr> <tr> <td>achternaam</td> <td> <telerik:radtextbox id="ctrllastname" runat="server"></telerik:radtextbox></td> <td> <asp:panel id="pnlastname" runat="server" width="25px"> <asp:requiredfieldvalidator id="requiredfieldvalidator1" validationgroup="group1" runat="server" controltovalidate="ctrllastname" errormessage="lastname required" display="dynamic" enableclientscript="true">*</asp:requiredfieldvalidator> </asp:panel> </td> </tr> <tr> <td colspan="2"> <telerik:radbutton id="ctrlcreate" runat="server" text="voeg toe"></telerik:radbutton> </td> </tr> <tr> <td colspan="3"> <asp:label id="lblred" style="color: red" runat="server" width="159px"></asp:label> <asp:label id="lblgreen" style="color: green" runat="server" width="159px"></asp:label></td> </tr> <tr> <td></td> <td colspan="2"> <asp:panel id="panel3" runat="server"> <asp:validationsummary id="validationsummary" runat="server" width="174px" bordercolor="red" borderwidth="1px" headertext="list of errors" enableclientscript="true" displaymode="bulletlist" validationgroup="group1"></asp:validationsummary> </asp:panel> </td> </tr> </table> </telerik:radajaxpanel> </div> <telerik:radajaxloadingpanel id="loadingpanel1" runat="server" mindisplaytime="300"> </telerik:radajaxloadingpanel> </div> <script type="text/javascript"> function validate() { page_clientvalidate('group1'); } </script>
code behind:
public partial class manageaccountcontrol : system.web.ui.usercontrol { rootrepos _repos; protected override void oninit(eventargs e) { initializecomponent(); base.oninit(e); } protected void page_load(object sender, eventargs e) { _repos = new rootrepos(); initctrls(); foreach (basevalidator validator in page.validators) { validator.enableclientscript = true; } } private void initializecomponent() { this.ctrlcreate.click += new system.eventhandler(ctrlcreate_click); this.load += new system.eventhandler(page_load); } private void initctrls() { lblred.text = string.empty; lblgreen.text = string.empty; } protected void ctrlcreate_click(object sender, eventargs e) { if (page.isvalid) { lblred.text = "name registered: "; lblgreen.text = ctrllastname.text + " " + ctrlfirstname.text; } else { lblred.text = "account not registered! validation error."; } } private bool checkifuserexists() { if (_repos.accountrepos.getsingle(ctrlemail.text) != null) return true; else return false; } private data.account createaccount(guid partyid) { data.account account = new data.account(); account.partyid = partyid; account.name = ctrlemail.text; return account; } private data.party createparty() { data.party party = new data.party(); party.partyid = guid.newguid(); party.lastname = ctrllastname.text; party.name = ctrlfirstname.text + " " + ctrllastname.text; party.firstname = ctrlfirstname.text; return party; } }
thank you!
Comments
Post a Comment