asp.net页面传值测试实例代码(前后台)
2024-07-10 12:45:07
供稿:网友
WebForm_1.aspx内容如下:
代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm_1.aspx.cs" Inherits="页面传值.WebForm_1" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Table ID="TableLogin" runat='server'>
<asp:TableRow>
<asp:TableCell><label>用户名:</label></asp:TableCell>
<asp:TableCell><asp:TextBox ID="UserName" runat="server" Width="150px"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><label>密码:</label></asp:TableCell>
<asp:TableCell><asp:TextBox ID="PassWord" runat="server" Width="150px"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><label>验证密码:</label></asp:TableCell>
<asp:TableCell><asp:TextBox ID="ConfimPWD" runat="server" Width="150px"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><asp:Button ID="Confirm" runat="server" Text="确认" Width="50px" OnClick="Confirm_Click" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
</body>
</html>
WebForm_2.aspx页面如下:
代码如下:
<%@ Reference Page="~/WebForm_1.aspx" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm_2.aspx.cs" Inherits="页面传值.WebForm_2" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
WebForm_1.aspx.cs文件如下:
代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace 页面传值
{
public partial class WebForm_1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string un//得到用户名
{
get
{
return UserName.Text;
}
}
public string pwd//得到密码
{
get
{
return PassWord.Text;
}
}
public string conpwd//得到确认密码
{
get
{
return ConfimPWD.Text;
}
}
/// <summary>
/// 向WebForm_2.aspx页面传值
/// </summary>