以下代码在VS2008中测试通过

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm1.aspx.cs" Inherits="WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox><br /> <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class WebForm1 : System.Web.UI.Page
{
public string Time
{
get { return DateTime.Now.ToString(); }
}
public string TestFun()
{
return "Function of WebForm1 Called";
} protected void Page_Load(object sender, EventArgs e)
{
Context.Items.Add("Context", "Context from Form1"); }
protected void Button1_Click(object sender, EventArgs e)
{
//this.TextBox2.Text =Request ["TextBox1"].ToString ();
Server.Transfer("WebForm2.aspx", true);//第二个参数为false时,WebForm2.aspx中不能获得TextBox1的内容 }
}

WebForm2.aspx  源码

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WebForm2.aspx.cs" Inherits="WebForm2" %>
<%@ Reference Page="~/WebForm1.aspx"%><%--注意这里--%> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Literal ID="Literal1" runat="server"></asp:Literal>
</div>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string strTxt = "";
WebForm1 oForm = (WebForm1)this.Context.Handler;
strTxt += "Value of Textbox:" + Request.Form["TextBox1"] + "<br>";
strTxt += "Time Property:" + oForm.Time + "<br>";
strTxt += "Context String:" + Context.Items["Context"].ToString() + "<br>";
strTxt += oForm.TestFun() + "<br>";
Literal1.Text = strTxt;
}
}

摘自与:http://blog.csdn.net/vchao13/article/details/5004502

ASP.NET中使用Server.Transfer()方法在页间传值 实例的更多相关文章

  1. 在ASP.NET MVC应用程序中实现Server.Transfer()类似的功能

    在ASP.NET MVC应用程序中,如果使用Server.Transfer()方法希望将请求转发到其它路径或者Http处理程序进行处理,都会引发“为xxx执行子请求时出错”的HttpException ...

  2. 在 ASP.NET 中使用 jQuery.load() 方法

    今天就让我们看看在 ASP.NET 中使用 jQuery.load() 方法来调用 ASP.NET 的方法,实现无刷新的加载数据. 使用 jQuery 的朋友应该知道可以使用 jQuery.load( ...

  3. asp.net中导出Excel的方法

    一.asp.net中导出Excel的方法: 本文转载 在asp.net中导出Excel有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址输出在浏览器上:一种是将文件直接将文件输出 ...

  4. ASP.net中网站访问量统计方法代码(在线人数,本月访问,本日访问,访问流量,累计访问)

    一.建立一个数据表IPStat用于存放用户信息 我在IPStat表中存放的用户信息只包括登录用户的IP(IP_Address),IP来源(IP_Src)和登录时间 (IP_DateTime),些表的信 ...

  5. asp.net中导出Execl的方法

    一.asp.net中导出Execl的方法: 在 asp.net中导出Execl有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址 输出在浏览器上:一种是将文件直接将文件输出流写给 ...

  6. Server.Transfer方法,Server.Execute方法和Response.Redirect方法有什么异同

    (1)Server.Transfer方法: Server.Transfer("m2.aspx");//页面转向(服务器上执行). 服务器停止解析本页,保存此页转向前的数据后,再使页 ...

  7. ASP.NET中连接数据库的各种方法

    ASP.NET中连接数据库的各种方法 连接SQL数据库的方法:(一).在Web.Config中创建连接字符串:1.<add name="ConnectionString" c ...

  8. 判断asp.net中session过期的方法

    判断asp.net中session过期的方法 转载自:http://www.cnblogs.com/xilipu31/archive/2013/04/12/3016830.html 方法一:最麻烦也是 ...

  9. ASP.NET中几种加密方法

    下面就是ASP.NET中几种加密方法.加密算法有两种,也就是上面提到的MD5和SHA1,这里我举的例子是以MD5为例,SHA1大致相同,只是使用的类不一样. MD5的全称是Message-Digest ...

随机推荐

  1. 实时计算storm流程架构总结

    hadoop一般用在离线的分析计算中,而storm区别于hadoop,用在实时的流式计算中,被广泛用来进行实时日志处理.实时统计.实时风控等场景,当然也可以用在对数据进行实时初步的加工,存储到分布式数 ...

  2. 转-CSS优先级(权重)解析

    1.多个选择器可能会选择同一个元素,有3个规则,从上到下重要性降低: !important的用户样式 !important的作者样式 作者样式 用户样式 浏览器定义的样式 2. CSS规范为不同类型的 ...

  3. ssh原理[转]

    SSH是每一台Linux电脑的标准配置. 随着Linux设备从电脑逐渐扩展到手机.外设和家用电器,SSH的使用范围也越来越广.不仅程序员离不开它,很多普通用户也每天使用. SSH具备多种功能,可以用于 ...

  4. mybatis 关联关系查询 java

    <mapper namespace="com.rrz.modules.awardrecord.dao.CheckAwardsDao"> <resultMap ty ...

  5. 谷歌浏览器js debug

  6. Python 中的GIL

    GIL:Global Interpreter Lock,     全局解释器锁定,是指python虚拟机在执行多线程程序时,任一时刻只有一个线程在执行,这使得多线程程序无法充分利用CPU.对于一般的多 ...

  7. IOS 类似网易新闻客户端内容滚动菜单跟随居中组件

    需求分析: 1.类似网易新闻客户端页面滚动组件.菜单栏对应菜单项一直居中 2.点击菜单栏可以切换到对应的page 3.滑动页面可以自动切换相应的菜单.并且对应的菜单栏居中显示 4.初始化时可以自定义菜 ...

  8. html5 读写sqlite数据库

    var db = openDatabase('MyData','','My Database',102400); //首先它创建一个数据库表,里面有3个字段 db.transaction(functi ...

  9. 【其他】MySql数据库的安装与卸载

    一.安装 1.首先下载安装包,包含服务端和客户端 2.添加用户组.用户 secondary1:~ # groupadd mysql secondary1:~ # useradd -g mysql -d ...

  10. SQL函数学习(三):convert()函数

    格式:CONVERT(data_type,expression[,style])说明:此样式一般在时间类型(datetime,smalldatetime)与字符串类型(nchar,nvarchar,c ...