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 ();}...}