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

2016-02-19 11:54 48 1 收藏

下面图老师小编要向大家介绍下2个页面间不通过Session与url的传值方式,看起来复杂实则是简单的,掌握好技巧就OK,喜欢就赶紧收藏起来吧!

【 tulaoshi.com - Web开发 】

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

WebForm1:
%@ Page language="c#" Codebehind="WebForm1.aspx.cs" Inherits="chuandi.WebForm1" %
HTML
 HEAD
  titleWebForm1/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");
  }
 }
}

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

WebForm2:
%@ Page language="c#" Codebehind="WebForm2.aspx.cs" Inherits="chuandi.WebForm2" %
%@ Reference Page="WebForm1.aspx" %
HTML
 HEAD
  titleWebForm2/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");
  }
 }

(本文来源于图老师网站,更多请访问https://www.tulaoshi.com/webkaifa/)

来源:https://www.tulaoshi.com/n/20160219/1599072.html

延伸阅读
阿里云邮箱MX记录验证不通过怎么办   MX记录验证不通过的常见问题及解决方法: (1)以前存在纯域名的CNAME记录,则可能会导致MX记录无法生效。 (2)有些域名提供商的域名MX设置默认会加上域名本身为后缀,此时需要在后面加上一个"." 。 (3)某些域名提供商要求只能使用IP来设置MX记录,当前我们还不能完全支...
标签: 电脑入门
电脑管家Win10检测系统默认语言不通过,升级到Windows 10系统对于系统默认语言的要求是系统默认语言必须为中文简体或者中文繁体,如果是其他默认语言的话,则不会通过。 有的系统是英文+中文补丁的方式实现的中文界面,不属于本次升级支持的情况。 如何修改系统语言: 1、打开控制面板区域和语言; 2、格式选项卡,格式选择中文(简体,...
标签: ASP
<% ' BEGIN USER CONSTANTS ' To just use a DSN, the format is shown on the next line: 'Const DSN_NAME = "DSN=ASP101email" ' Two other samples I used it with.  Left in as syntax examples for DSN-less connections 'Const DSN_NAME = "DBQ=C:\InetPub\wwwroot\asp101\samples\database.mdb;Driver={Microsoft Acces...
标签: Web开发
function pCall()  {   __doPostBack('Button1','');  } 可以直接刷新页面,执行后台代码。 (控件名如果含有":" ,需要预先替换为"$") 即使控件设为隐藏,(如button的visible = false),页面上没有生成button, 仍然可以这样直接使用。
标签: 电脑入门
电脑管家Win10检测BIOS不通过解决方法,BIOS是一组固化到计算机内主板上一个ROM新品上的程序,它保存着计算机最重要的基本输入输出的程序、开机后自检程序和系统自启动程序,它可从CMOS中读写系统设置的具体信息。其主要功能是为计算机提供最底层的、最直接的硬件设置和控制。 微软在Windows 10操作系统中,加入了对BIOS程序的严格检测,以确...

经验教程

118

收藏

50
微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部