c# - Validation not firing on submit after clicking reset button -
validation not firing(not showing error messages) when click submit button after clicking cancel(reset) button.
validation works when click submit button first before cancel button. have included javascript validations 2 fields , 1 validation clearing error messages. thats
(javascript validation 2 textboxes alone working in above condition)
aspx code
<body> <h3>project details</h3> <form id="form1" runat="server"> <table align="center" cellpadding="30" > <!----- project name ----------------------------------------------------------> <tr> <td>project name</td> <td> <p>::</p> </td> <td class="pi"> <p> <asp:textbox id="txtprojectname" runat="server" ></asp:textbox> <asp:requiredfieldvalidator id="rfvprojectname" runat="server" controltovalidate="txtprojectname" errormessage="mandatory field" setfocusonerror="true"></asp:requiredfieldvalidator> </p> </td> </tr> <!----- description ----------------------------------------------------------> <tr> <td>description</td> <td> <p>::</p> </td> <td class="pi"> <p> <asp:textbox id="txtdescription" runat="server" xmlns:asp="#unknown"></asp:textbox> <asp:requiredfieldvalidator id="rfvdescription" runat="server" controltovalidate="txtdescription" errormessage="mandatory field"></asp:requiredfieldvalidator> </p> </td> </tr> <!----- company name ----------------------------------------------------------> <tr> <td>company name</td> <td> <p>::</p> </td> <td class="pi"> <asp:dropdownlist id="ddlcompanyname" autopostback="true" onselectedindexchanged="ddlcompanyname_selectedindexchanged" runat="server" ></asp:dropdownlist> <asp:customvalidator runat="server" id="customvalidator1" clientvalidationfunction="jsfunctionvalidate" errormessage="please select atleast 1 module"></asp:customvalidator> </td> <!----- project status ----------------------------------------------------------> <tr> <td>project status</td> <td> <p>::</p> </td> <td class="pi"> <asp:radiobuttonlist id="rblprojectstatus" runat="server" style="display: inline" repeatdirection="horizontal"> <asp:listitem text="success" value="rbsuccess"></asp:listitem> <asp:listitem text="failure" value="rbfailure"></asp:listitem> </asp:radiobuttonlist> <asp:requiredfieldvalidator id="rfvprojectstatus" runat="server" controltovalidate="rblprojectstatus" errormessage="mandatory field"></asp:requiredfieldvalidator> </tr> </td> </tr> <!----- website url ----------------------------------------------------------> <td>website url</td> <asp:textbox id="txtwebsiteurl" runat="server"></asp:textbox> <asp:regularexpressionvalidator id="revwebsiteurl" runat="server" controltovalidate="txtwebsiteurl" errormessage="enter valid url" validationexpression="http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?"></asp:regularexpressionvalidator> <asp:requiredfieldvalidator id="rfvwebsiteurl" runat="server" controltovalidate="txtwebsiteurl" display="static" errormessage="it mandatory"></asp:requiredfieldvalidator> </td> </tr> <!----- project completed in ----------------------------------------------------------> <td>project completed in</td> <asp:checkboxlist id="chklprojectcompleted" runat="server" style="display: inline" repeatdirection="horizontal"> <asp:listitem id="chkproject1" runat="server" text="<1 month"></asp:listitem> <asp:listitem id="chkproject2" runat="server" text="1-2 month"></asp:listitem> </asp:checkboxlist> <asp:customvalidator runat="server" id="cvmodulelist" clientvalidationfunction="validatemodulelist" errormessage="please select atleast 1 module"></asp:customvalidator> </p> </td> </tr> <!----- project started at----------------------------------------------------------> <td>project started at</td> <asp:textbox id="txtprojectdate" readonly="true" runat="server" ontextchanged="txtprojectdate_textchanged1"></asp:textbox> <asp:imagebutton id="btnshowcalendar" runat="server" onclick="btnshowcalendar_click" imageurl="d:\calendar4.png" causesvalidation="false" width="16px" /> <asp:calendar id="calprojectdate" runat="server" onselectionchanged="calprojectdate_selectionchanged" visible="false"></asp:calendar> <asp:requiredfieldvalidator id="rfvprojectdate" runat="server" controltovalidate="txtprojectdate" errormessage="mandatory"></asp:requiredfieldvalidator> </td> </tr> <!----- save ----------------------------------------------------------> <asp:button id="btnsave" runat="server" text="save" onclick="btnsave_click" /> <asp:button id="btnclear" runat="server" text="clear" onclick="btnclear_click" onclientclick="return aa()" /></td> </tr> </table> <div> <asp:gridview id="gddisplay" runat="server" backcolor="white" bordercolor="#999999" borderstyle="none" borderwidth="1px" cellpadding="3" gridlines="vertical" width="1027px"> <alternatingrowstyle backcolor="#dcdcdc" /> <footerstyle backcolor="#cccccc" forecolor="black" /> <headerstyle backcolor="#000084" font-bold="true" forecolor="white" /> <pagerstyle backcolor="#999999" forecolor="black" horizontalalign="center" /> <rowstyle backcolor="#eeeeee" forecolor="black" /> <selectedrowstyle backcolor="#008a8c" font-bold="true" forecolor="white" /> <sortedascendingcellstyle backcolor="#f1f1f1" /> <sortedascendingheaderstyle backcolor="#0000a9" /> <sorteddescendingcellstyle backcolor="#cac9c9" /> <sorteddescendingheaderstyle backcolor="#000065" /> </asp:gridview> </div> </form> </body> </html>
aspx.cs code
i have included clear fields , basic functionalities alone!
protected void btnsave_click(object sender, eventargs e) { int a; try { con.open(); oraclecommand cmd = con.createcommand(); string interests = string.empty; foreach (listitem item in this.chklprojectcompleted.items) /*populating selected checkbox values interests string */ if (item.selected) interests += item + ","; string projectcompletion= interests.trimend('?', '.', ','); /*method trim trailing comma in database */ if (rblprojectstatus.selectedindex>0) /*populating radio button 0 & 1 values */ { = 1; } else { = 0; } cmd.commandtext = "insert cmppoject(projectname,description,company,projectstatus,websiteurl,completedin,startedin)values('" + txtprojectname.text + "','" + txtdescription.text + "','" + ddlcompanyname.selectedindex + "','" + + "','" + txtwebsiteurl.text + "','" + projectcompletion + "','" + txtprojectdate.text + "')"; cmd.executenonquery(); response.write("<script>alert('registration success')</script>"); txtdescription.text = ""; txtprojectdate.text = ""; rblprojectstatus.selectedindex = -1; txtprojectname.text = ""; txtwebsiteurl.text = ""; calprojectdate.visible = false; chkproject1.selected = false; chkproject2.selected = false; ddlcompanyname.selectedindex = 0; } catch(exception ex) { response.write("<script>alert('sorry,some error occured! please try again!')</script>"); } { con.close(); con.open(); oraclecommand cmd = con.createcommand(); cmd.commandtext = " select projectname,company,projectstatus,startedin,completedin cmppoject"; datatable dt = new datatable(); cmd.commandtype = commandtype.text; oracledataadapter da = new oracledataadapter(cmd); datatable dt = new datatable(); da.fill(dt); gddisplay.datasource = dt; gddisplay.databind(); // return dt; con.close(); } } protected void btnclear_click(object sender, eventargs e) { txtdescription.text = ""; txtprojectdate.text = ""; txtprojectname.text = ""; txtwebsiteurl.text = ""; calprojectdate.visible = false; chkproject1.selected = false; chkproject2.selected = false; ddlcompanyname.selectedindex = 0; rblprojectstatus.selectedindex = -1; rfvdescription.errormessage = ""; rfvprojectdate.errormessage = ""; rfvprojectname.errormessage = ""; rfvprojectstatus.errormessage =""; rfvwebsiteurl.errormessage = ""; revwebsiteurl.errormessage = ""; }
pls me solve out.
Comments
Post a Comment