protected void Button1_Click(object sender, EventArgs e)
{
if (txtname.Text.Trim().Equals("mr") && txtpwd.Text.Trim().Equals("mrsoft"))
{
Session["username"] = txtname.Text.Trim();
if (ckbauto.Checked)
{
if (Request.Cookies["username"] == null)
{
Response.Cookies["username"].Expires = DateTime.Now.AddDays();
Response.Cookies["userpwd"].Expires = DateTime.Now.AddDays();
Response.Cookies["username"].Value = txtname.Text.Trim();
Response.Cookies["userpwd"].Value = txtpwd.Text.Trim();
}
}
Response.Redirect("admin.aspx");
}
else
{
ClientScript.RegisterStartupScript(this.GetType(),"","alert('用户名或密码错误!');",true);
}
}
protected void txtname_TextChanged(object sender, EventArgs e)
{
if (Request.Cookies["username"] != null)
{
if (Request.Cookies["username"].Value.Equals(txtname.Text.Trim()))
{
txtpwd.Attributes["value"] = Request.Cookies["userpwd"].Value;
}
}
}

注: 对于txtname控件, 需要将其的AutoPostBack属性, 设置为True, 这样当用户输入用户名之后, 会自动回发到服务器, 执行TextChanged事件

014. asp.net实现记住密码的功能的更多相关文章

  1. MiniTwitter记住密码等功能实现

    一.SharedPreferences的用法:(相关实现功能的只是了解) 由于SharedPreferences是一个接口,而且在这个接口里没有提供写入数据和读取数据的能力.但它是通过其Editor接 ...

  2. (四)SpringMVC之使用cookie实现记住密码的功能

    注意:因为实现记住密码的功能需要用到json,所以需要加上这条语句: <script type="text/javascript" src="scripts/jqu ...

  3. Cookie实现记住密码的功能

    一.什么是Cookie cookie是一种WEB服务器通过浏览器在访问者的硬盘上存储信息的手段.Cookie的目的就是为用户带来方便,为网站带来增值.虽然有着许多误传,事实上Cookie并不会造成严重 ...

  4. JavaWeb学习----Cookie实现记住密码的功能

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  5. 通过js来设置cookie和读取cookie,实现登陆时记住密码的功能

    function setCookie(){ //设置cookie var loginCode = $("#login_code").val(); //获取用户名信息 var pwd ...

  6. 登陆一个系统时,前端js实现的验证,记住密码等功能

    记住密码部分: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <m ...

  7. 超简单的localStorage实现记住密码的功能

    HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessionStorage - 针对一个 session 的数据存储 之前,这些都是由 coo ...

  8. android: SharedPreferences实现记住密码功能

    既然是实现记住密码的功能,那么我们就不需要从头去写了,因为在上一章中的最佳实 践部分已经编写过一个登录界面了,有可以重用的代码为什么不用呢?那就首先打开 BroadcastBestPractice 项 ...

  9. 记住密码"功能的正确设计

    Web上的用户登录功能应该是最基本的功能了,可是在我看过一些站点的用户登录功能后,我觉得很有必要写一篇文章教大家怎么来做用户登录功能.下面的文章告诉大家这个功能可能并没有你所想像的那么简单,这是一个关 ...

随机推荐

  1. 通过一个Thinkphp完成多个项目

    1.单独取压缩包中的Thinkphp文件夹 2.在单独的项目内创建一个引入文件 3.通过浏览器访问该index.php 会创建相应的目录

  2. PE文件格式

    以下内容摘录自<加密与解密>: 为了在PE文件中避免有确定的内存地址,出现了相对虚拟地址(RVA)的概念.RVA只是内存中的一个简单的相对于PE文件装入地址的偏移位置.它是一个“相对”地址 ...

  3. HDU 3932

    http://acm.hdu.edu.cn/showproblem.php?pid=3932 一定范围的平面上给一些点,求到这些点的最大距离最小,和上一题的题意正好相反,稍微改一下就可以 这个问题又叫 ...

  4. Why does my ListView scroll to the top when navigating backwards?

    I’ve seen a few people asking this question. They have a page which contains a ListView and when an ...

  5. 使用WebMatrix发布网站到Windows Azure

    1. 在本地机安装 WebMatrix, 安装Windows Azure SDK 2. 登录Windows Azure, 网站 > 创建一个新网站或选择已有网站 3. 在发布应用程序,选择下载发 ...

  6. C++学习笔记3:一些错误

    错误1:执行程序后,控制台闪烁后退出 处理办法: (1)添加头文件:#include <iostream> (2)在程序返回前添加代码: std::cin.clear();//清除错误标志 ...

  7. 101. Symmetric Tree

    Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...

  8. 143. Reorder List

    Given a singly linked list L: L0→L1→…→Ln-1→Ln,reorder it to: L0→Ln→L1→Ln-1→L2→Ln-2→… You must do thi ...

  9. js confirm用法

    <script> $('.tzshanchu').click(function(){ if(confirm('是否确认删除')){ alert('删除了') } });</scrip ...

  10. SQL参数化查询--最有效可预防SQL注入攻击的防御方式

    参数化查询(Parameterized Query 或 Parameterized Statement)是访问数据库时,在需要填入数值或数据的地方,使用参数 (Parameter) 来给值. 在使用参 ...