In the. aspx file
Copy Code code as follows:
...
<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 username" font-size= "Small" forecolor= "Gray"/>
...
In the. aspx.cs file
Copy Code code as follows:
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
This.txtUser_Id.Focus ();
if (! Object.Equals (request.cookies["UserID"], NULL)
{
Create a cookie object that implements remembering user names
HttpCookie Readcookie = request.cookies["UserID"];
This.txtUser_Id.Text = Readcookie. Value;
}
}
}
private void Createcookie ()
{
Create a Cookie Object
HttpCookie cookie = new HttpCookie ("UserID");
To determine whether a CheckBox control is selected
if (this.cbxRemeberUser.Checked)
{
Store a user number in a created cookie object
Cookie. Value = This.txtUser_Id.Text;
}
Gets the expiration time of the created cookie object
Cookie. Expires = DateTime.MaxValue;
Add the created cookie object to the internal cookie collection
Response.appendcookie (cookie);
}
protected void Btninsert_click (object sender, ImageClickEventArgs e)
{
...
if (object. Equals (request.cookies["UserID"], NULL)
{
Invoke Custom Method Createcookie () store user name
Createcookie ();
}
Else
{
Createcookie ();
}
...
}