ASP.NET記住登陸用戶名的具體實現(xiàn)
.aspx文件中
…
<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="記住用戶名" Font-Size="Small" ForeColor="gray"/>
…
.aspx.cs文件中
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.txtUser_Id.Focus();
if (!Object.Equals(Request.Cookies["UserID"], null))
{
//創(chuàng)建一個Cookie對象,實現(xiàn)記住用戶名
HttpCookie readcookie = Request.Cookies["UserID"];
this.txtUser_Id.Text = readcookie.Value;
}
}
}
private void CreateCookie()
{
//創(chuàng)建一個Cookie對象
HttpCookie cookie = new HttpCookie("UserID");
//判斷Checkbox控件是否被選中
if (this.cbxRemeberUser.Checked)
{
//將用戶編號存儲到創(chuàng)建的Cookie對象中
cookie.Value = this.txtUser_Id.Text;
}
//獲取創(chuàng)建的Cookie對象的過期時間
cookie.Expires = DateTime.MaxValue;
//將創(chuàng)建的Cookie對象添加到內(nèi)部Cookie集合中
Response.AppendCookie(cookie);
}
protected void btnInsert_Click(object sender, ImageClickEventArgs e)
{
…
if (object.Equals(Request.Cookies["UserID"], null))
{
//調(diào)用自定義方法 CreateCookie()存儲用戶名
CreateCookie();
}
else
{
CreateCookie();
}
…
}
相關(guān)文章
.NET Core 微信小程序退款步驟——(統(tǒng)一退款)
這篇文章主要介紹了.NET Core 微信小程序退款步驟——(統(tǒng)一退款),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-09-09asp.net(C#)實現(xiàn)功能強大的時間日期處理類完整實例
這篇文章主要介紹了asp.net(C#)實現(xiàn)功能強大的時間日期處理類,封裝了針對日期與時間的各種常用的判斷與計算功能,非常方便實用,需要的朋友可以參考下2016-06-06aspnet_regsql.exe 工具注冊數(shù)據(jù)庫的圖文方法
自 ASP.NET 2.0 起,微軟在 ASP.NET 上新增了很多功能,其中包括 Membership , Role , Profile 等等諸多功能2010-03-03asp.net 不用GridView自帶刪除功能,刪除一行數(shù)據(jù)
數(shù)據(jù)表一定要有個ID的主鍵值,你的gridview要設(shè)定一下DataKeyNames="ID"這個屬性值,接下的事件就好多了,寫個OnRowDeleting事件就可以了。2009-11-11基于ASP.NET MVC的ABP框架入門學(xué)習(xí)教程
ABP是基于Windows系統(tǒng)上.NET Framework環(huán)境的Web開發(fā)框架,這里我們基于.NET的Visual Studio開發(fā)環(huán)境,來共同進(jìn)入基于ASP.NET MVC的ABP框架入門學(xué)習(xí)教程2016-06-06