c# - How to stop loading the whole HTML page in registration form ? - ASP.NET -
i'm working asp.net web application . have done registration form whenever user type username
or email
loads whole first_home
page ! how can stop loading whole page ? have setup constraint in database username
, email
avoid duplication.
the html code:
<table align="left" class="auto-style8" dir="rtl"> <tr> <td class="auto-style13">username </td> <td class="auto-style10"> <br /> <asp:textbox id="textboxusername" runat="server" autopostback="true" height="25px" width="223px" forecolor="#990033" ontextchanged="textboxusername_textchanged"></asp:textbox> <br /> </td> <td class="auto-style11"> <asp:requiredfieldvalidator id="requiredfieldvalidator2" runat="server" controltovalidate="textboxusername" errormessage="write username"></asp:requiredfieldvalidator> </td> <td> </td> </tr> <tr> <td class="auto-style13">password</td> <td class="auto-style10"> <br /> <asp:textbox id="textboxpassword" runat="server" height="25px" width="223px" forecolor="#990033" textmode="password" ontextchanged="textboxpassword_textchanged"></asp:textbox> <br /> </td> <td class="auto-style11"> <asp:requiredfieldvalidator id="requiredfieldvalidator3" runat="server" controltovalidate="textboxpassword" errormessage="must write password"></asp:requiredfieldvalidator> </td> <td> </td> </tr> <tr> <td class="auto-style13">confirm password </td> <td class="auto-style10"> <br /> <asp:textbox id="textboxcpassword" runat="server" height="25px" width="223px" forecolor="#990033" textmode="password" ontextchanged="textboxcpassword_textchanged"></asp:textbox> <br /> </td> <td class="auto-style11"> <asp:requiredfieldvalidator id="requiredfieldvalidator4" runat="server" controltovalidate="textboxcpassword" errormessage="must write password"></asp:requiredfieldvalidator> <br /> <asp:comparevalidator id="comparevalidator1" runat="server" controltocompare="textboxpassword" controltovalidate="textboxcpassword" errormessage="wrong password"></asp:comparevalidator> </td> <td> </td> </tr> <tr> <td class="auto-style13">email</td> <td class="auto-style10"> <br /> <asp:textbox id="textboxemail" runat="server" autopostback="true" height="25px" width="223px" forecolor="#990033" textmode="email" ontextchanged="textboxemail_textchanged"></asp:textbox> <br /> </td> <td class="auto-style11"> <asp:requiredfieldvalidator id="requiredfieldvalidator5" runat="server" controltovalidate="textboxemail" errormessage="must write email"></asp:requiredfieldvalidator> <br /> <asp:regularexpressionvalidator id="regularexpressionvalidator1" runat="server" controltovalidate="textboxemail" errormessage="the email no valid" validationexpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:regularexpressionvalidator> </td> <td> </td> </tr> <tr> <td class="auto-style13"> </td> <td class="auto-style10"> <asp:button id="button6" runat="server" onclick="button6_click" text="done" forecolor="#990033" /> </td> <td class="auto-style11"> </td> <td> </td> </tr> </table>
the first_home.aspx.cs code:
public partial class first_home : system.web.ui.page { protected void page_load(object sender, eventargs e) { if (ispostback) { sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["mydatabase"].connectionstring); conn.open(); // check if username taken before string checkuser = "select count(*) users username='" + textboxusername.text + "'"; sqlcommand com = new sqlcommand(checkuser, conn); int temp = convert.toint32(com.executescalar().tostring()); if (temp == 1) { response.write("error"); } conn.close(); } } protected void button6_click(object sender, eventargs e) { try { sqlconnection conn = new sqlconnection(configurationmanager.connectionstrings["mydatabase"].connectionstring); conn.open(); string insertquery = "insert users (username,password,email) values (@username, @password, @email)"; sqlcommand com = new sqlcommand(insertquery, conn); com.parameters.addwithvalue("@username", textboxusername.text); com.parameters.addwithvalue("@password", textboxpassword.text); com.parameters.addwithvalue("@email", textboxemail.text); com.executenonquery(); conn.close(); response.redirect("seller_registration.aspx"); } catch (exception ex) { response.write("error "); } }
also database constraint :
constraint [ak_users_email] unique nonclustered ([email] asc), constraint [ak_users_username] unique nonclustered ([username] asc),
remove autopostback="true"
attribute 2 controls.
those 2 controls causing postback
whenever typing , focusing out of control. reason behind whole page load.
Comments
Post a Comment