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)