首页 > 开发 > 综合 > 正文

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

2024-07-21 02:16:07
字体:
来源:转载
供稿:网友

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


收集最实用的网页特效代码!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表