新客网WWW.XKER.COM:致力做中国最专业的网络学院!
学院: 操作系统 - 网络应用 - 服务器 - 网络安全 - 工具软件 - 办公软件 - Web开发 - 数据库 - 网页设计 - 图形图像 - 媒体动画 - 硬件学堂 - 存储频道 - QQ专区
您的位置:首页 > 软件开发 > .Net开发 > VC.NET教程 > 正文:.net页面间的参数传递简单实例

.net页面间的参数传递简单实例

新客网 XKER.COM 2006-05-12 来源: 收藏本文


  }

  }  

  public string EMail

  {

  get

  {

  return TextBox2.Text;

  }

  }

  然后调用Server.Transfer方法

  private void Button1_Click

  (object sender, System.EventArgs e)

  {

  Server.Transfer("anotherwebform.aspx");

  }

  目标页面代码:

  private void Page_Load

  (object sender, System.EventArgs e)

  {

  //create instance of source web form

  WebForm1 wf1;

  //get reference to current handler instance

  wf1=(WebForm1)Context.Handler;

  Label1.Text=wf1.Name;

  Label2.Text=wf1.EMail;

  }  

 

  在ASP.NET 2.0中启用了跨页面传送功能,其功能和用法在以后在做介绍!
  
  页面之间传递值

  方式1:  

  在接收页 的html代码里加上一行:   

   WebForm1 fp=(WebForm1)Context.Handler;

   this.TextBox1.Text=fp.name; //name 是第一页的public变量  

  Context 提供对整个当前上下文(包括请求对象)的访问。您可以使用此类共享页之间的信息。

  方式2:GET方式

   在发送页

   public int sum=0;  

   int i =int.Parse(this.TextBox1.Text)*2;  

   Server.Transfer("WebForm2.aspx?sum="+i);  

   接收页

   this.TextBox1.Text=Request["sum"].ToString();

   or this.TextBox1.Text=Request.Params["sum"].ToString();

   this.TextBox1.Text=Request.QueryString["sum"];  

  方法3:全局变量  

   发送页:

   Application["sum"]=this.TextBox1.Text;

   Server.Transfer("WebForm2.aspx"); 

   接收页:

   this.TextBox1.Text=(string)Application["sum"];  

  Application实质上是整个虚拟目录中所有文件的集合,如果想在整个应用范围内使用某个变量值,Application对象将是最佳的选择  

  在这里用Session[""]的方法雷同

  方法4:  

   发送页:

   1.定义静态变量: public static string str="";

   2. str=this.TextBox1.Text;

   Server.Transfer("webform2.aspx");

   接收页:

   1.引入第一页的命名空间:using WebApplication1;

   2 this.TextBox1.Text=WebForm1.str;

共2页: 上一页 [1] [2] 下一页
收藏】 【评论】 【推荐】 【投稿】 【打印】 【关闭
发表评论
要记得去论坛讨论,点击注册新会员匿名评论
评论内容:不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。