asp.net页面传值的几种方法大全
2010-10-13 23:33
489 查看
这些方法都是在网上搜到的,现在只是临时写一下,过段时间再修改。
testA.aspx后台代码:
TestB.aspx后台代码:
testA.aspx后台代码:
using System; using System.Web; namespace WebApplication1 { public partial class testA : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // PassValueByCookie(); // Response.Redirect("TestB.aspx"); // PassValeByContext(); PassValueByApplication(); Server.Transfer("TestB.aspx"); } /// <summary> /// 使用Server.Transfer方法 /// </summary> private void PassValueByRedirect() { Response.Redirect("TestB.aspx?A=b&AA=12&AAA=45"); } /// <summary> /// 使用Cookie对象变量 /// </summary> private void PassValueByCookie() { HttpCookie cookie_name = new HttpCookie("name"); cookie_name.Value = "12"; Response.AppendCookie(cookie_name); } /// <summary> /// Context /// </summary> public void PassValeByContext() { string Str = "Hello World"; this.Context.Items.Add("Text", Str); } /// <summary> /// 使用Application 对象变量 /// </summary> private void PassValueByApplication() { Application["name"] ="Hello!"; } public string Name { get { return Label1.Text; } } } }
TestB.aspx后台代码:
using System; namespace WebApplication1 { public partial class TestB : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // GetValueByQueryString(); //GetValueByCookie(); // GetValueByPageFlow(); // GetValueByContext(); GetValueByApplication(); } /// <summary> /// /// </summary> private void GetValueByQueryString() { string a = Request.QueryString["A"].ToString(); string aa = Request.QueryString["AA"].ToString(); string aaa = Request.QueryString["AAA"].ToString(); } private void GetValueByCookie() { string name = Request.Cookies["name"].Value.ToString(); } private void GetValueByPageFlow() { testA newWeb= Context.Handler as testA;; //实例a窗体 string name; name = newWeb.Name; } private void GetValueByContext() { string a= this.Context.Items["Text"].ToString();//HttpContext接收数据 } private void GetValueByApplication() { string name; Application.Lock(); name = Application["name"].ToString(); Application.UnLock(); } } }
相关文章推荐
- ASP.NET中页面传值的几种方法
- asp.net Context.Handler 页面间传值的几种方法
- ASP.NET实现页面传值的几种方法小结
- ASP.NET页面传值的几种方法
- ASP.NET实现页面传值的几种方法
- asp.net Context.Handler 页面间传值的几种方法
- 转:浅析ASP.NET中页面传值的几种方法
- ASP.NET实现页面传值的几种方法
- asp.net页面间传值的几种方法 表单提交 传送页面代码 复制代码 <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server
- asp.net页面间传值的几种方法
- asp.net 页面间传值的几种方法
- asp.net页面间传值的几种方法
- ASP.NET 页面间传值的几种方法
- asp.net页面间传值的几种方法
- ASP.NET中页面传值的几种方法
- ASP.NET实现页面传值的几种方法小结
- asp.net页面传值的几种方法比较
- asp.net 页面间传值的几种方法
- ASP.NET中页面传值的几种方法(很实用)
- ASP.NET中页面传值的几种方法(转载)