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

 更新时间:2006年09月28日 00:00:00   作者:  

下面是全部代码,已经编译通过。
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");
  }
 }

相关文章

  • ASP.NET 站点地图(sitemap)简明教程

    ASP.NET 站点地图(sitemap)简明教程

    毕业设计折腾了近一个月的时间,也将近完工阶段。下个礼拜六是论文答辩时间,所以今天晚上就抽空想去弄一下站点地图。不怕大侠们笑话,我在以前还真没弄过这些。以前开发过几个项目都是系统类,也就没怎么涉及了
    2012-04-04
  • .NET Core 委托原理解析(最新推荐)

    .NET Core 委托原理解析(最新推荐)

    委托是 .NET Core 中一个非常强大的特性,它允许你将方法作为参数传递、存储和调用,本文将介绍.NET Core委托原理解析,感兴趣的朋友一起看看吧
    2025-01-01
  • ASP.NET Session的七点认识小结

    ASP.NET Session的七点认识小结

    ASP.NET Session的使用当中我们会遇到很多的问题,那么这里我们来谈下经常出现的一些常用ASP.NET Session的理解
    2011-07-07
  • 浅析.net core 抛异常对性能影响

    浅析.net core 抛异常对性能影响

    在.net项目中使用自定义异常来处理业务很爽,但是又担心大量抛业务异常存在性能问题,下面通过本文介绍.net core 抛异常对性能影响的求证之路,需要的朋友可以参考下
    2022-06-06
  • 详解log4net的使用

    详解log4net的使用

    这篇文章主要介绍了log4net的使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-04-04
  • Quartz在.NET中的使用教程

    Quartz在.NET中的使用教程

    Quartz是一个强大、开源、轻量级的任务调度框架,支持cron-like表达式其他一些优秀的特性。这篇文章主要介绍了Quartz在.NET中的使用,需要的朋友可以参考下
    2021-12-12
  • asp.net 文件下载功能函数代码整理

    asp.net 文件下载功能函数代码整理

    asp.net下文件下载功能代码,fullFilename 要下载的文件的路径+文件名,需要的朋友可以参考下。
    2010-04-04
  • asp.net(vb.net)获取真实IP的函数

    asp.net(vb.net)获取真实IP的函数

    asp.net(vb.net)获取真实IP的函数,需要的朋友可以参考下。
    2010-11-11
  • 数据绑定之DataFormatString使用介绍

    数据绑定之DataFormatString使用介绍

    DataFormatString是很多Asp.Net控件都有的属性,如GridView等等,下面简单介绍一下这个属性,感兴趣的朋友不要错过
    2013-10-10
  • .NET实现文件跨服务器上传下载的方法

    .NET实现文件跨服务器上传下载的方法

    这篇文章主要给大家介绍了.NET文件如何实现跨服务器上传下载的方法,文中通过图片介绍的很详细,相信对大家的理解和学习具有一定的参考借鉴价值,有需要的朋友们可以跟着小编来一起学习学习吧。
    2016-12-12

最新评论