62,041
社区成员
发帖
与我相关
我的任务
分享
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EditUser.aspx.cs" Debug="true" Inherits="EditUser" %>
<!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" >
<head runat="server">
<title>无标题页</title>
<link rel="stylesheet" type="text/css" href="aspnet2.0basecss.css">
</head>
<body>
<form id="form1" runat="server">
<div align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="height: 66px; text-align: left;" colspan="2">
<span style="font-size: 24pt">修改用户</span></td>
</tr>
<tr>
<td colspan="2" style="height: 9px">
</td>
</tr>
<tr>
<td style="width: 22px; height: 30px;">
</td>
<td style="width: 100px; height: 30px;">
</td>
</tr>
<tr>
<td width="20%" style="text-align: right">
<span style="font-size: 12pt">用户名称:</span></td>
<td style="width: 100px; height: 30px;">
<asp:TextBox ID="UserName" runat="server" Enabled="false"></asp:TextBox></td>
</tr>
<tr>
<td width="20%" style="text-align: right; height: 30px;">
<span style="font-size: 12pt">电子邮件:</span></td>
<td style="text-align: left; height: 30px;">
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvEmail" runat="server" ErrorMessage="电子邮件不能为空" Display="Dynamic" ControlToValidate="Email"></asp:RequiredFieldValidator>
<asp:RegularExpressionValidator ID="revEmail" runat="server" ErrorMessage="电子邮件格式不正确" Display="dynamic" ControlToValidate="Email" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td style="height: 30px;" colspan="2">
</td>
</tr>
<tr>
<td style="height: 30px; width: 22px;">
</td>
<td style="height: 30px; text-align: left">
<asp:Button ID="ModifyBtn" runat="server" Text="修改" CssClass="ButtonCss" Width="90" OnClick="ModifyBtn_Click"/>
<asp:Button ID="ReturnBtn" runat="server" Text="返回" CssClass="ButtonCss" Width="90" OnClick="ReturnBtn_Click"/></td>
</tr>
<tr>
<td style="width: 22px; height: 30px;">
</td>
<td style="width: 100px; height: 30px;">
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
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;
using System.Data.SqlClient;
public partial class EditPwd : System.Web.UI.Page
{
private int nUserID = -1;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserID"] != null)
{
if (Int32.TryParse(Session["UserID"].ToString(), out nUserID) == false)
{
return;
}
}
else
{
Response.Redirect("~/Default.aspx");
}
if (!Page.IsPostBack)
{
//判断参数是否正确
if (nUserID > -1)
{
BindUserData();
}
}
}
private void BindUserData()
{
User user = new User();
SqlDataReader dr = user.GetSingleUser(nUserID);
if (dr.Read())
{
UserName.Text = dr["UserName"].ToString();
}
dr.Close();
}
protected void ModifyBtn_Click(object sender, EventArgs e)
{
User user = new User();
try
{
user.UpdateUserPassword(nUserID, NewPassword.Text.Trim());
Response.Write("<script>alert('修改密码成功,请妥善管保好您的信息!')</script>");
}
catch (Exception ex)
{
Response.Redirect("~/ErrorPage.aspx?ErrorMsg="+ex.Message+"&ErrorUrl="+Request.Url.ToString());
}
}
protected void ReturnBtn_Click(object sender, EventArgs e)
{
Response.Redirect("~/UserManage.aspx");
}
}
<asp:TextBox ID="Email" runat="server"></asp:TextBox>
后放置一个RequiredFieldValidator控件和一个RegularExpressionValidator控件