Instance submitted to the background through form submit in Asp.net

Source: Internet
Author: User

Code In the front-end :

<Body> <Div id = "TOP"> </div> <Form ID = "login" name = "login" Action = "? Action = login "method =" Post "> <Div id =" center "> <Div id =" center_left "> </div> <Div id =" center_middle "> <Div class = "user"> <label> User Name: <input type = "text" name = "username" id = "username"/> </label> </div> <br/> <Div class = "user"> <label> password: <input type = "password" name = "userpassword" id = "userpassword"/> </label> </div> <Div id = "center_middle_right"> </div> <Div id = "center_submit"> <Div class = "button">  </div> <Div class =" button ">  </div> <Div id =" center_right "> </div> </form> <Div id =" footer "> </div> </body>

Execute form. Submit () to pass parameters in form through the image click event.

Backend CS code:

Protected string action = ""; mybaseclass mydata = new mybaseclass (); protected class userlogininfo {Public String username = ""; Public String userpassword = "";} protected userlogininfo _ userlogininfo = new userlogininfo (); // create the object protected void page_load (Object sender, eventargs e) {init_webcontrols ();} public void init_webcontrols () {try {If (! String. isnullorempty (request. querystring ["action"]) // obtain the {Action = request. querystring ["action"]. trim (). tolower (); // remove spaces and write them smaller} switch (Action) {Case "login": If (! String. isnullorempty (request. Form ["username"]) &! String. isnullorempty (request. form ["userpassword"]) // obtain the {_ userlogininfo parameter in form. username = request. form ["username"]. tostring (); _ userlogininfo. userpassword = request. form ["userpassword"]. tostring (); string user = "select Administrator name, password from T _ administrator table where Administrator name = '" + _ userlogininfo. username + "'and Password ='" + _ userlogininfo. userpassword + "'"; if (mydata. readdataset (user ). tables [0]. rows. count = 1) {respons E. redirect ("Main. aspx ", false); // prevents response. execution of the end method termination page} else {response. write ("<script language = JavaScript> alert ('incorrect password or username. Please try again! '); </SCRIPT> ") ;}} break ;}catch (exception ex) {Throw new exception (ex. Message );}}

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.