webform--Registration Verification

Source: Internet
Author: User

The alternate use of server and client controls is to get the values of each control, either by using C # or JS directly to determine if the condition is met.

Here is the server control as an example, as for the client control needs to write JS code

1, USERBF Public classuserbf{PrivateMydbdatacontext _context;  PublicUSERBF () {_context=NewMydbdatacontext (); }     Public BOOLSelect (stringUserName,stringUSERPWD)//Verify user name    {        varquery = _context. Loginuser.where (p=>p.username==username&&p.userpwd==userpwd); returnQuery. Count () >0; }     Public BOOLLogin (stringUserID)//Verify that the ID is unique    {        varquery = _context. Loginuser.where (P = p.userid==UserID); returnQuery. Count () >0; }     Public voidInsert (stringUseridstringUsernamestringuserpwd) {Loginuser Data=NewLoginuser (); Data. UserID=userid; Data. UserName=username; Data. Userpwd=userpwd; _context.        Loginuser.insertonsubmit (data); _context.    SubmitChanges (); }}2, front desk design<form id="Form1"runat="Server"> <div> <center>"Label5"runat="Server"text="User id:"></asp:label>&nbsp;<asp:textbox id="TextBox2"runat="Server"Ontextchanged="textbox2_textchanged"></asp:textbox><input id="Button3"Type="Button"Value="Unique authentication"runat="Server"onserverclick="Button3_serverclick"><br> <asp:label id="Label6"runat="Server"text="User name:"></asp:label>&nbsp;<asp:textbox id="TextBox3"runat="Server"></asp:TextBox><br> <asp:label id="Label7"runat="Server"text="Password:"></asp:label>&nbsp;&nbsp;&nbsp;<asp:textbox id="TextBox4"runat="Server"></asp:TextBox><br> <asp:label id="Label8"runat="Server"text="Confirm Password:"></asp:label><asp:textbox id="TextBox5"runat="Server"></asp:TextBox><br> <asp:button id="Button4"runat="Server"text="Register"Enabled="False"onclick="Button1_Click"/> </center> </div></ from>3, code for background write validation in C #protected voidButton1_Click (Objectsender, EventArgs e)//registration of the server    {        stringUserID =TextBox2.Text; stringUsername =TextBox3.Text; stringUserpwd =Textbox4.text; stringUserpwdagain =Textbox5.text; if(userid=="") {Response.Write ("<script>alert (' User ID cannot be empty!! ') </script>"); }        Else if(username=="") {Response.Write ("<script>alert (' User name cannot be empty!! ') </script>"); }        Else if(Userpwd = ="") { Response.Write ( "<script>alert (' user password cannot be empty!! ') </script> "); }        Else if(Userpwd! =Userpwdagain) {Response.Write ("<script>alert (' two times the password is not the same, please re-enter!! ') </script>"); }        Else        {            NewUSERBF ().            Insert (USERID,USERNAME,USERPWD); Response.Write ("<script>alert (' Registration successful!! ') </script>"); }    }    protected voidButton3_serverclick (Objectsender, EventArgs e)//Server unique Authentication    {        if(string. Isnullorwhitespace (TextBox2.Text)) {Response.Write ("<script>alert (' User ID cannot be empty!! ') </script>"); }        Else        {            BOOLisOK =NewUSERBF ().            Login (TextBox2.Text); if(isOK) {Response.Write ("<script>alert (' This ID already exists, please change!! ') </script>"); }            Else{Response.Write ("<script>alert (' Congratulations you can use!!! ') </script>"); Button4.enabled=true; }        }    }    protected voidTextbox2_textchanged (Objectsender, EventArgs e) {button4.enabled=false; }

→ →

→ → →

→ →→ →

webform--Registration Verification

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.