1.使用QueryString变量
传送的值会显示在浏览器之地址栏中
所以传递一个或多个安全性要求不高或是结构简单之数值时,
可以使用这个方法,用QueryString变量接收值
QueryString传值例子:
第一个网页:
创建x.aspx的页面
创建y.aspx的页面
Application对象所有用户都有效。其常用之方法用Lock和UnLock。
编辑
Form这个肯定是大家使用中最多的用法之一,是基于HTML,可作为静态页面传送数据而且数据量比较大,而且数据保密,
所以,在传值比较多对收集起来的数据又需要保密的时候才用Form传值是相当方便的。
x.aspx页面前台:
后台:
y.aspx页面后台:
操作与Application类似,作用于用户个人,所以,过量之存储会导致服务器内存资源之耗尽。
x.aspx页面前台:
y.aspx页面后台:
5使用Cookie对象变量
编辑
Cookie和Session一样,但是有个本质之区别,即Cookie是存放在客户端之,而session是存放在服务器端之。
而且Cookie之使用要配合ASP.NET内置对象Request来使用。
x.aspx页面前台:
y.aspx页面后台:
6使用Server.Transfer方法
这个才可以说是面象对象开发所使用之方法,其使用Server.Transfer方法把流程从当前页面引导到另一个页面中,
新之页面使用前一个页面之应答流,所以这个方法是完全面象对象之,简洁有效。
x.aspx页面前台:
后台:
y.aspx页面后台
传送的值会显示在浏览器之地址栏中
所以传递一个或多个安全性要求不高或是结构简单之数值时,
可以使用这个方法,用QueryString变量接收值
QueryString传值例子:
第一个网页:
创建x.aspx的页面
在前台写个超连接:
<a href="y.aspx?zhi=传的值 ">链接地址传送</a>
第二个网站:创建y.aspx的页面
在后台写:
protected void Page_Load(object sender, EventArgs e)
{
string zhi = Request.QueryString["zhi"];//第一种QueryString传值
Response.Write(zhi);
}
2.使用Application 对象变量
Application对象所有用户都有效。其常用之方法用Lock和UnLock。
x.aspx页面前台:
<form id="form1" runat="server">
<div>
名字:<asp:TextBox ID="NameTxt" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" text="Application上传" OnClick="Button1_Click"/>
</div>
</form>
x.aspx页面后台:
protected void Button1_Click(object sender, EventArgs e)
{
Application["name"] = NameTxt.Text;//把值存进去
Response.Redirect("y.aspx");
}
y.aspx页面后台:
private void Page_Load(object sender, EventArgs e)
{
string name;
Application.Lock();
name = Application["name"].ToString();//把值取出来
Application.UnLock();
Response.Write(name);
}
3使用Form表单
编辑
Form这个肯定是大家使用中最多的用法之一,是基于HTML,可作为静态页面传送数据而且数据量比较大,而且数据保密,
所以,在传值比较多对收集起来的数据又需要保密的时候才用Form传值是相当方便的。
x.aspx页面前台:
<form id="form1" runat="server">
<div>
名字:<asp:TextBox ID="NameTex" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Form上传" OnClick="Button1_Click" />
</div>
</form>
后台:
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("<form name='submit1' method='post' action='y.aspx'>");//把值提交到y.aspx
Response.Write("<input id=\"myxi\" name=\"myxi\" type=\"hidden\" value=\"" + NameTex.Text+ "\"/>");//建一个隐藏字段设置name,id名字为myxi,value值为文本里面的值
Response.Write("</form>");
Response.Write("<script>");
Response.Write("document.submit1.submit()");//把刚刚form提交上去
Response.Write("</script>");
}
y.aspx页面后台:
private void Page_Load(object sender, EventArgs e)
{
string name;
name = Request.Form["myxi"].ToString();
Response.Write(name);
}
4使用Session变量
操作与Application类似,作用于用户个人,所以,过量之存储会导致服务器内存资源之耗尽。
x.aspx页面前台:
<form id="form1" runat="server">
<div>
名字:<asp:TextBox ID="NameTex" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Session上传" OnClick="Button1_Click"/>
</div>
</form>
后台:
protected void Button1_Click(object sender, EventArgs e)
{
Session["name"] = NameTex.Text;
Response.Redirect("y.aspx");
}
y.aspx页面后台:
protected void Page_Load(object sender, EventArgs e)
{
string name;
name = Session["name"].ToString();
Response.Write(name);
}
5使用Cookie对象变量
编辑
Cookie和Session一样,但是有个本质之区别,即Cookie是存放在客户端之,而session是存放在服务器端之。
而且Cookie之使用要配合ASP.NET内置对象Request来使用。
x.aspx页面前台:
<form id="form1" runat="server">
<div>
名字:<asp:TextBox ID="NameTex" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Cookie上传" OnClick="Button1_Click" />
</div>
</form>
后台:
protected void Button1_Click(object sender, EventArgs e)
{
Request.Cookies.Clear();
HttpCookie cookie_name = new HttpCookie("name");
cookie_name.Value = NameTex.Text;
Response.AppendCookie(cookie_name);
Response.Redirect("y.aspx");
}
y.aspx页面后台:
protected void Page_Load(object sender, EventArgs e)
{
string name;
name =Request.Cookies["name"].Value.ToString();
Response.Write(name);
}
6使用Server.Transfer方法
这个才可以说是面象对象开发所使用之方法,其使用Server.Transfer方法把流程从当前页面引导到另一个页面中,
新之页面使用前一个页面之应答流,所以这个方法是完全面象对象之,简洁有效。
x.aspx页面前台:
<form id="form1" runat="server">
<div>
名字:<asp:TextBox ID="NameTex" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Server.Transfer上传" OnClick="Button1_Click" />
</div>
</form>
后台:
public string Name
{
get { return NameTex.Text; }
}
protected void Button1_Click(object sender, EventArgs e)
{
Server.Transfer("y.aspx");
}
y.aspx页面后台
protected void Page_Load(object sender, EventArgs e)
{
x newWeb; //实例x窗体
newWeb = (x)Context.Handler;
string name;
name = newWeb.Name;
Response.Write(name);
}