2个页面间不通过Session与url的传值方式_实用技巧

下面是全部代码,已经编译通过。
Chuandi(传递)是名字空间

WebForm1:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" Inherits="chuandi.WebForm1" %>
<HTML>
 <HEAD>
  <title>WebForm1</title>
 </HEAD>
 <body>
  <form id="Form1" method="post" runat="server">
   <asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
   <asp:Button id="Button1" runat="server" Text="传"></asp:Button>
  </form>
 </body>
</HTML>
using System;
namespace chuandi
{
 public class WebForm1 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.TextBox TextBox1;
  protected System.Web.UI.WebControls.Button Button1;
  public string Text1
  {
   get
   {
    return this.TextBox1.Text;
   }
  }
  private void Page_Load(object sender, System.EventArgs e)
  {}
  override protected void OnInit(EventArgs e)
  {
   InitializeComponent();
   base.OnInit(e);
  }
  private void InitializeComponent()
  {   
   this.Button1.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);
  }
  private void Button1_Click(object sender, System.EventArgs e)
  {
   Server.Transfer("WebForm2.aspx");
  }
 }
}

WebForm2:
<%@ Page language="c#" Codebehind="WebForm2.aspx.cs" Inherits="chuandi.WebForm2" %>
<%@ Reference Page="WebForm1.aspx" %>
<HTML>
 <HEAD>
  <title>WebForm2</title>
 </HEAD>
 <body>
  <form id="Form1" method="post" runat="server">
   <asp:Label id="Label1" runat="server">Label</asp:Label>
   <asp:Button id="Button1" runat="server" Text="返回"></asp:Button>
  </form>
 </body>
</HTML>
using System;
namespace chuandi
{
 public class WebForm2 : System.Web.UI.Page
 {
  protected System.Web.UI.WebControls.Button Button1;
  protected System.Web.UI.WebControls.Label Label1;
  public chuandi.WebForm1 wf1;
  private void Page_Load(object sender, System.EventArgs e)
  {
   if(!IsPostBack)
   {
    wf1=(chuandi.WebForm1)Context.Handler;
    Label1.Text="上页传来的是:"+wf1.Text1;
   }
  }
  override protected void OnInit(EventArgs e)
  {
   InitializeComponent();
   base.OnInit(e);
  }
  private void InitializeComponent()
  {   
   this.Button1.Click += new System.EventHandler(this.Button1_Click);
   this.Load += new System.EventHandler(this.Page_Load);
  }
  private void Button1_Click(object sender, System.EventArgs e)
  {
   Server.Transfer("WebForm1.aspx");
  }
 }

时间: 2024-08-03 14:00:37

2个页面间不通过Session与url的传值方式_实用技巧的相关文章

2个页面间不通过Session与url的传值方式

session|页面 下面是全部代码,已经编译通过.Chuandi(传递)是名字空间 WebForm1:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" Inherits="chuandi.WebForm1" %><HTML> <HEAD>  <title>WebForm1</title> </HEAD> <bod

2个页面间不通过Session与url的传值方式。

下面是全部代码,已经编译通过.Chuandi(传递)是名字空间 WebForm1:<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" Inherits="chuandi.WebForm1" %><HTML> <HEAD>  <title>WebForm1</title> </HEAD> <body>  <

asp.net WebForm页面间传值方法_实用技巧

ASP.NET WEB FORMS 给开发者提供了极好的事件驱动开发模式.然而这种简单的应用程序开发模式却给我们带来了一些小问题,举个例子,在传统的ASP应用程序中,你能够通过POST方法很容易的把一个值或多个值从一个页面传送到另一个页面(request()/request.form()/request.querystring()),用同样的方法在ASP.NET中实现有点麻烦.在这里,通过其他方式来解决这种情形.ASP.NET为我们提供了三种方式,一种是可以通过用QueryString来传送相应

ASP.NET 跨页面传值方法_实用技巧

1. 使用QueryString变量 QueryString是一种非常简单的传值方式,他可以将传送的值显示在浏览器的地址栏中.如果是传递一个或多个安全性要求不高或是结构简单的数值时,可以使用这个方法.但是对于传递数组或对象的话,就不能用这个方法了.下面是一个例子: a.aspx的C#代码 复制代码 代码如下: private void Button1_Click(object sender, System.EventArgs e) { string s_url; s_url = "b.aspx?

asp.net 页面转向 Response.Redirect, Server.Transfer, Server.Execute的区别_实用技巧

Response.Redirect 简单地发送一条消息到浏览器,告诉浏览器定位到另一个页面.你可以使用下面的代码将用户引导到另一个页面: Response.Redirect("WebForm2.aspx") 或者 Response.Redirect("http://www.cnnas.com/") Server.Transfer 也是通过一条语句将用户引导到另一页面,比如:Server.Transfer("WebForm2.aspx").不过,这

iframe跨域与session失效问题的解决办法_实用技巧

何为跨域跨域session/cookie? 也就是第三方session/cookie.第一方session/cookie指的是访客当前访问的网站给访客的浏览器设置的seesion /cookie, 会被存储在访客的计算机上.第三方session/cookie指的是当前访问的网站中会加载(嵌入)另外第三方的网站代码,例如促销广告,那么第三方网 站也会在访客的计算机上添加session/cookie,这种就是第三方session/cookie. 我的问题 在开发讯息在线产品(http://iap.p

解决uploadify使用时session发生丢失问题的方法_实用技巧

今天在使用uploadify时发现session会发生丢失的情况,经过一番研究发现,其丢失并不是真正的丢失,而是在使用Flash上传控件的时候使用的session机制和asp.net中的不相同.为解决这个问题使用两种方案,下面进行介绍 第一种:修改Gobal前台aspx页面: $("#uploadify").uploadify({ 'uploader': '/LZKS/Handler/BigFileUpLoadHandler.ashx', 'swf': '/LZKS/Scripts/u

asp.net session丢失的解决方法小结_实用技巧

现在我就把原因和解决办法写出来. ASP.NET Session丢失原因: 由于Asp.net程序是默认配置,所以Web.Config文件中关于Session的设定如下: < sessionState mode='InProc' stateConnectionString='tcpip=127.0.0.1:42424' sqlConnectionString='data source=127.0.0.1;Trusted_Connection=yes' cookieless='true' time

Asp.net中安全退出时清空Session或Cookie的实例代码_实用技巧

概览: 网站中点击退出,如果仅仅是重定向到登录/出页面,此时在浏览器地址栏中输入登录后的某个页面地址如主页,你会发现不用登录就能访问.这种所谓的退出并不是安全的. 那么怎样做到安全退出呢? 那就是点击退出后清空相应的Session或Cookie. 清空Session的代码: Session.Clear(); Session.Abandon(); 清除Cookie的正确代码(假设Cookie名称为UserInfo): if (Request.Cookies["UserInfo"] !=