webform1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="dynamicweb6_1.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>用户注册</h3>
用户名:<asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />
密码:<asp:TextBox ID="txtPassword" runat="server"></asp:TextBox><br />
<asp:Button ID="btnSubmit" runat="server" Text="注册" OnClick="btnSubmit_Click" /><br />
<asp:Label ID="lblTips" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
webform1.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace dynamicweb6_1
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (String.IsNullOrEmpty(txtName.Text))
{
lblTips.Text = "输入用户名";
txtName.Focus();
}
else if (string.IsNullOrEmpty(txtPassword.Text))
{
lblTips.Text = "输入密码";
txtPassword.Focus();
}
else
{
lblTips.Text = "注册成功";
string url1 = "WebForm2.aspx?name=" + txtName.Text
+ "&pwd=" + Convert.ToBase64String(System.Text.Encoding.Default.GetBytes(txtPassword.Text));
Response.Redirect(url1);
}
}
}
}
webform2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs" Inherits="dynamicweb6_1.WebForm2" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="lblMsg" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
webform2.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace dynamicweb6_1
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["name"] != null)
{
lblMsg.Text = "用户名是" + Request.QueryString["name"]
+ ",密码是" + System.Text.Encoding.Default.GetString(Convert.FromBase64String(Request.QueryString["pwd"]));
}
}
}
}