Get the values from the foreground page, upload the obtained values to the background, and do simple login verification (not associated with the database)

Source: Internet
Author: User

Idea: Using jquery's Ajax

Front Code:

1 <Body>2     <formID= "Form1"runat= "Server">3     <Div>4         <Table>5             <TR>6                 <TD>User name:</TD>7                 <TD>8                     <inputtype= "text"ID= "Name"name= "Username" />9                 </TD>Ten             </TR> One             <TR> A                 <TD>Password:</TD> -                 <TD> -                     <inputtype= "Password"ID= "pwd"name= "Userpwd" /> the                 </TD> -             </TR> -             <TR> -                 <TD> +                     <inputtype= "button"ID= "Btnok"value= "Login"/> -                 </TD> +             </TR> A         </Table> at     </Div> -     </form> - </Body>

Ajax Code:

1 //the front desk of Ajax is empty page2$ (document). Ready (function () {3 //to bind a click event to a label on the foreground page, write a method4$ ("#btnOk"). Bind ("click",function () {5     //take the data from the front page input6         varUsername = document.getElementById ("name"). Value;7         varUserpwd = document.getElementById ("pwd"). Value;8 $.ajax ({9URL: "Loginbackstage.aspx",TenType: "POST", OneData: "Username=" + UserName + "&userpwd=" + userpwd + "", AErrorfunction () { -Alert ("Error"); -             }, theSuccessfunction(DA) { -                 varFlag =da.tostring (); -                 if(Flag = = 1) { -self.location = ' main.aspx '; +                 } -             } +         }); A     }); at});

In the background of the AJAX empty page Page_Load write the background code, do login verification

1 protected voidPage_Load (Objectsender, EventArgs e)2     {3         //Login Verification4         stringUsername = request["UserName"];5         stringUserpwd = request["userpwd"];6 7         intFlag =0;8         Try9         {Ten             if(Username = ="Zhang San"&& Userpwd = ="1001") One             { AFlag =1; - Response.Write (flag. ToString ()); -  the             } -         } -         Catch(Exception ex) -         { +  -             Throwex; +         } A}

Get the values from the foreground page, upload the obtained values to the background, and do simple login verification (not associated with the database)

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.