Remember the User Login Name

Source: Internet
Author: User

In the. aspx File

... <Asp: TextBox ID = "txtUser_Id" runat = "server" MaxLength = "4" Width = "120px" BorderColor = "LightSlateGray" BorderWidth = "1px"> </asp: textBox>... <Asp: ImageButton ID = "btnInsert" runat = "server" ImageUrl = "~ /Images/Login. GIF "OnClick =" btnInsert_Click "/>... <Asp: CheckBox ID = "cbxRemeberUser" runat = "server" Text = "Remember User Name" Font-Size = "Small" ForeColor = "gray"/>...

 

. Aspx. cs File

Protected void Page_Load (object sender, EventArgs e) {if (! IsPostBack) {this.txt User_Id.Focus (); if (! Object. equals (Request. cookies ["UserID"], null) {// create a Cookie object to remember the username HttpCookie readcookie = Request. cookies ["UserID"]; this.txt User_Id.Text = readcookie. value ;}} private void CreateCookie () {// create a Cookie object HttpCookie cookie = new HttpCookie ("UserID"); // determine whether the Checkbox control is selected if (this. cbxRemeberUser. checked) {// store the user ID to the Cookie object created in the cookie. value = this.txt User_Id.Text;} // obtain the expiration time of the Cookie object created c Ookie. expires = DateTime. maxValue; // Add the Cookie object to the internal Cookie set. appendCookie (cookie);} protected void btnInsert_Click (object sender, ImageClickEventArgs e ){... If (object. equals (Request. cookies ["UserID"], null) {// call the custom method CreateCookie () to store the username CreateCookie () ;}else {CreateCookie ();}...}

 

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.