asp.net

位置:IT落伍者 >> asp.net >> 浏览文章

asp.net页面传值测试实例代码


发布日期:2019年04月08日
 
asp.net页面传值测试实例代码

WebForm_aspx内容如下:

复制代码 代码如下:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm_aspxcs" Inherits="页面传值WebForm_" %>
<!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "
<html xmlns="
<head runat="server">
<title></title>
</head>
<body>
<form id="form" 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="px"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><label>密码</label></asp:TableCell>
<asp:TableCell><asp:TextBox ID="PassWord" runat="server" Width="px"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><label>验证密码</label></asp:TableCell>
<asp:TableCell><asp:TextBox ID="ConfimPWD" runat="server" Width="px"></asp:TextBox></asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell><asp:Button  ID="Confirm" runat="server" Text="确认" Width="px"  OnClick="Confirm_Click" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>
</form>
</body>
</html>


WebForm_aspx页面如下

复制代码 代码如下:
<%@ Reference Page="~/WebForm_aspx" %>
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm_aspxcs" Inherits="页面传值WebForm_" %>
<!DOCTYPE html PUBLIC "//WC//DTD XHTML Transitional//EN" "
<html xmlns="
<head runat="server">
<title></title>
</head>
<body>
<form id="form" runat="server">
<div>
</div>
</form>
</body>
</html>


WebForm_aspxcs文件如下

复制代码 代码如下:
using System;
using SystemCollectionsGeneric;
using SystemLinq;
using SystemWeb;
using SystemWebUI;
using SystemWebUIWebControls;
namespace 页面传值
{
public partial class WebForm_ : SystemWebUIPage
{
protected void Page_Load(object sender EventArgs e)
{
}
public string un//得到用户名
{
get
{
return UserNameText;
}
}
public string pwd//得到密码
{
get
{
return PassWordText;
}
}
public string conpwd//得到确认密码
{
get
{
return ConfimPWDText;
}
}
/// <summary>
/// 向WebForm_aspx页面传值
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Confirm_Click(object sender EventArgs e)
{
//QueryString页面传值
//string url = "WebForm_aspx?un=" + UserNameText + "&userpassword=" + PassWordText + "&conPwd=" + ConfimPWDText;
//ResponseRedirect(url);
//Session传值
//Session["un"] = UserNameText;
//Session["pwd"] = PassWordText;
//Session["conpwd"] = ConfimPWDText;
//ServerTransfer("WebForm_aspx");
//使用cookie对象传值
//HttpCookie cookie_name = new HttpCookie("un");
//cookie_nameValue = UserNameText;
//HttpCookie cookie_pwd = new HttpCookie("pwd");
//cookie_pwdValue = PassWordText;
//HttpCookie cookie_conpwd = new HttpCookie("conpwd");
//cookie_conpwdValue = ConfimPWDText;
//ResponseAppendCookie(cookie_name);
//ResponseAppendCookie(cookie_pwd);
//ResponseAppendCookie(cookie_conpwd);
//ServerTransfer("WebForm_aspx");
//使用application对象传值类似session传值作用范围全局所有用户
//Application["un"] = UserNameText;
//Application["pwd"] = PassWordText;
//Application["conpwd"] = ConfimPWDText;
//ResponseRedirect("WebForm_aspx");
ServerTransfer("WebForm_aspx");
}
}
}


WebForm_aspxcs文件如下

复制代码 代码如下:
using System;
using SystemCollectionsGeneric;
using SystemLinq;
using SystemWeb;
using SystemWebUI;
using SystemWebUIWebControls;
namespace 页面传值
{
public partial class WebForm_ : SystemWebUIPage
{
protected void Page_Load(object sender EventArgs e)
{
//QueryTransfer();
//SessionTransfer();
//CookieTransfer();
//ApplicationTransfer();
Transfer();
}
public void QueryTransfer()//接收QueryString传值来自于WebForm_页面的值
{
string strUserName = RequestQueryString["un"]ToString();
string strPassword = RequestQueryString["userpassword"]ToString();
string strPWD = RequestQueryString["conPwd"]ToString();
ResponseWrite("用户名为" + strUserName + "<br/>" + "密码为" + strPassword + "<br/>" + "确认密码为" + strPWD);
}
public void SessionTransfer()//接收session传值来自于WebForm_页面的值
{
string strUserName = Session["un"]ToString();
string strPassword = Session["pwd"]ToString();
string strPWD = Session["conpwd"]ToString();
ResponseWrite("用户名为" + strUserName + "<br/>" + "密码为" + strPassword + "<br/>" + "确认密码为" + strPWD);
SessionRemove("un");
SessionRemove("pwd");
SessionRemove("conpwd");
}
public void CookieTransfer()//接收cookie传值来自于WebForm_页面的值
{
string strUserName = RequestCookies["un"]ValueToString();
string strPassword = RequestCookies["pwd"]ValueToString();
string strPWD = RequestCookies["conpwd"]ValueToString();
ResponseWrite("用户名为" + strUserName + "<br/>" + "密码为" + strPassword + "<br/>" + "确认密码为" + strPWD);
}
public void ApplicationTransfer()//接收Application传值来自于WebForm_页面的值
{
ApplicationLock();
string strUserName = Application["un"]ToString();
string strPassword = Application["pwd"]ToString();
string strPWD = Application["conpwd"]ToString();
ApplicationUnLock();
if (strPassword != strPWD)
{
ResponseWrite("您确认的密码错误请重新输入!<br/>");
ServerTransfer("WebForm_aspx");
}
ResponseWrite("用户名为" + strUserName + "<br/>" + "密码为" + strPassword + "<br/>" + "确认密码为" + strPWD);
}
public void Transfer()//Transfer传值来自WebForm_aspx页面的值
{
WebForm_ wf;
wf = (WebForm_)ContextHandler;
string strUserName = wfun;
string strPassword = wfpwd;
string strPWD = wfconpwd;
ResponseWrite("用户名为" + strUserName + "<br/>" + "密码为" + strPassword + "<br/>" + "确认密码为" + strPWD);
}
}
}


本人水平有限还请各位朋友多多指教!

               

上一篇:ASP.NET4实用方法Url Routing的使用

下一篇:Asp.net中判断一个session是否合法的方法