.net之旅-用户登录框架(39)
来源:互联网 发布:2k online for mac 编辑:程序博客网 时间:2024/06/05 03:36
用户登录模块基本上是系统不可或缺的。本文将有关这方面的内容进行了简介和编码。不包括数据库部分。内容仅包括登录的验证(验证输入是否为空,并提示对应的出错信息)、回车即提交的实现。可以说是比较完整的一个框架。后面的部分我写完继续贴出。
1 建立网站在VS2005中,这个就不用我说了吧。
2 建立Index.aspx文件,系统同时建立Index.aspx.cs文件。
3 Index.aspx的代码:
<%...@ Page Language="C#" AutoEventWireup="true" CodeFile="Index.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script language="javascript">...
/**//* 回车提交表单 */
function SubmitKeyClick(button)
...{
if (event.keyCode == 13)
...{
document.getElementById("ButtonLogin").click();
}
}
</script>
<head runat="server">
<title>欢迎光临</title>
</head>
<body>
<form id="formLogin" runat="server">
<table>
<tr>
<td style="height: 26px; width: 67px;">用户名:</td>
<td style="width: 160px; height: 26px"><asp:TextBox ID="TextBoxUserId" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 67px">密 码:</td>
<td style="width: 160px"><asp:TextBox ID="TextBoxUserPwd" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td style="height: 26px; width: 160px;" align="center"><asp:Button ID="ButtonLogin" runat="server" Text="登录" ToolTip="用户登录" OnClick="ButtonLogin_Click" /></td>
</tr>
<tr>
<td></td>
<td><asp:Label ID="LabelError" runat="server" Text="用户名或密码错误" Visible="False" ForeColor="Red"></asp:Label></td>
</tr>
</table>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<script language="javascript">...
/**//* 回车提交表单 */
function SubmitKeyClick(button)
...{
if (event.keyCode == 13)
...{
document.getElementById("ButtonLogin").click();
}
}
</script>
<head runat="server">
<title>欢迎光临</title>
</head>
<body>
<form id="formLogin" runat="server">
<table>
<tr>
<td style="height: 26px; width: 67px;">用户名:</td>
<td style="width: 160px; height: 26px"><asp:TextBox ID="TextBoxUserId" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 67px">密 码:</td>
<td style="width: 160px"><asp:TextBox ID="TextBoxUserPwd" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td></td>
<td style="height: 26px; width: 160px;" align="center"><asp:Button ID="ButtonLogin" runat="server" Text="登录" ToolTip="用户登录" OnClick="ButtonLogin_Click" /></td>
</tr>
<tr>
<td></td>
<td><asp:Label ID="LabelError" runat="server" Text="用户名或密码错误" Visible="False" ForeColor="Red"></asp:Label></td>
</tr>
</table>
</form>
</body>
</html>
4 对应的cs文件代码:
/**//// ************************************************************
/// Copyright (C), 2006-2007, GUET.
/// FileName: Index.aspx.cs
/// Author: longronglin
/// Version : 1.0
/// Date: 2007-01-23
/// Description:
/// Function List:
/// 1. void Page_Load()
/// 2. void ButtonLogin_Click()
/// 3. void ValidInput()
/// History:
/// <author> <time> <version> <desc>
/// longronglin 2007/01/23 1.0 modify xxx .
/// *************************************************************
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
/**//// 回车提交表单处理,调用JavaScript处理。
/// onkeydown为TextBoxUserPwd的事件
/// SubmitKeyClick为对应的JavaScript函数,ButtonLogin为对应按钮ID的标识
TextBoxUserPwd.Attributes.Add("onkeydown", "SubmitKeyClick('ButtonLogin');");
/**////设置为焦点
TextBoxUserId.Focus();
}
/**//// <summary>
/// 登录按钮处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ButtonLogin_Click(object sender, EventArgs e)
...{
ValidInput();
}
/**//// <summary>
/// 验证输入是否合法,输入的用户名和密码不可为空。
/// </summary>
private void ValidInput()
...{
/**//// Page.IsPostBack响应客户端的反应判定,客户端重新提交则为真。
if (Page.IsPostBack)
...{
LabelError.Visible = false;
if (TextBoxUserId.Text.Length == 0)
...{
LabelError.Text = "用户名不可为空";
LabelError.Visible = true;
/**////设置为焦点
TextBoxUserId.Focus();
/**//// return用来退出当前函数
return;
}
if (TextBoxUserPwd.Text.Length == 0)
...{
LabelError.Text = "密码不可为空";
LabelError.Visible = true;
/**////设置为焦点
TextBoxUserPwd.Focus();
}
}
}
}
/// Copyright (C), 2006-2007, GUET.
/// FileName: Index.aspx.cs
/// Author: longronglin
/// Version : 1.0
/// Date: 2007-01-23
/// Description:
/// Function List:
/// 1. void Page_Load()
/// 2. void ButtonLogin_Click()
/// 3. void ValidInput()
/// History:
/// <author> <time> <version> <desc>
/// longronglin 2007/01/23 1.0 modify xxx .
/// *************************************************************
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
/**//// 回车提交表单处理,调用JavaScript处理。
/// onkeydown为TextBoxUserPwd的事件
/// SubmitKeyClick为对应的JavaScript函数,ButtonLogin为对应按钮ID的标识
TextBoxUserPwd.Attributes.Add("onkeydown", "SubmitKeyClick('ButtonLogin');");
/**////设置为焦点
TextBoxUserId.Focus();
}
/**//// <summary>
/// 登录按钮处理
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ButtonLogin_Click(object sender, EventArgs e)
...{
ValidInput();
}
/**//// <summary>
/// 验证输入是否合法,输入的用户名和密码不可为空。
/// </summary>
private void ValidInput()
...{
/**//// Page.IsPostBack响应客户端的反应判定,客户端重新提交则为真。
if (Page.IsPostBack)
...{
LabelError.Visible = false;
if (TextBoxUserId.Text.Length == 0)
...{
LabelError.Text = "用户名不可为空";
LabelError.Visible = true;
/**////设置为焦点
TextBoxUserId.Focus();
/**//// return用来退出当前函数
return;
}
if (TextBoxUserPwd.Text.Length == 0)
...{
LabelError.Text = "密码不可为空";
LabelError.Visible = true;
/**////设置为焦点
TextBoxUserPwd.Focus();
}
}
}
}
5 测试正确。
希望对大家有用。
- .net之旅-用户登录框架(39)
- .net之旅-用户登录框架2(40)
- Java web框架之用户登录需求设计
- “用户 'IIS APPPOOL/Classic .NET AppPool' 登录失败”之解决
- Delphi用户登录窗口框架
- Delphi用户登录窗口框架
- 权限之用户登录
- ASP.NET的用户登录
- asp.net用户登录代码
- ASP.NET 关于用户登录
- 登录判断 之 asp.net 使用继承类的Session,判断用户是否登录
- 登录之记住用户与自动登录
- 登录之记住用户与自动登录
- 登录之记住用户与自动登录
- Apache-mina框架学习之简单的用户登录与注册(MySql数据库)
- Spring学习之SpringMVC框架快速搭建实现用户登录功能
- SSM框架下的二手教材交易系统之用户登录(包括表单提前验证,ajax)
- Spring学习之SpringMVC框架快速搭建实现用户登录功能
- 在Linux下访问MS SQL Server数据库
- 用WPF和.NET开发的下一代Yahoo Messenger
- 下载PDF 格式的ASP.NET AJAX 备忘表
- 技巧和诀窍: 如何上传一个.SQL文件到远程主机并且执行它来部署一个SQL数据库
- 字符串转化成DATE类型
- .net之旅-用户登录框架(39)
- windows server 2003的设置技巧
- 我讨论WPF/E,Orcas,IIS7和MIX的采访录像
- 编写高性能Web应用程序的10个入门技巧
- 在CodeMash上作的ASP.NET 技巧和诀窍和LINQ讲座的讲义和演示代码
- 创建序列
- Visual Studio Orcas Web设计器集成进VS主体代码
- oracle
- 得到IP地址