ASP.NET中使用Server.Transfer()方法在页间传值 实例
以下代码在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()方法在页间传值 实例的更多相关文章
- 在ASP.NET MVC应用程序中实现Server.Transfer()类似的功能
在ASP.NET MVC应用程序中,如果使用Server.Transfer()方法希望将请求转发到其它路径或者Http处理程序进行处理,都会引发“为xxx执行子请求时出错”的HttpException ...
- 在 ASP.NET 中使用 jQuery.load() 方法
今天就让我们看看在 ASP.NET 中使用 jQuery.load() 方法来调用 ASP.NET 的方法,实现无刷新的加载数据. 使用 jQuery 的朋友应该知道可以使用 jQuery.load( ...
- asp.net中导出Excel的方法
一.asp.net中导出Excel的方法: 本文转载 在asp.net中导出Excel有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址输出在浏览器上:一种是将文件直接将文件输出 ...
- ASP.net中网站访问量统计方法代码(在线人数,本月访问,本日访问,访问流量,累计访问)
一.建立一个数据表IPStat用于存放用户信息 我在IPStat表中存放的用户信息只包括登录用户的IP(IP_Address),IP来源(IP_Src)和登录时间 (IP_DateTime),些表的信 ...
- asp.net中导出Execl的方法
一.asp.net中导出Execl的方法: 在 asp.net中导出Execl有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址 输出在浏览器上:一种是将文件直接将文件输出流写给 ...
- Server.Transfer方法,Server.Execute方法和Response.Redirect方法有什么异同
(1)Server.Transfer方法: Server.Transfer("m2.aspx");//页面转向(服务器上执行). 服务器停止解析本页,保存此页转向前的数据后,再使页 ...
- ASP.NET中连接数据库的各种方法
ASP.NET中连接数据库的各种方法 连接SQL数据库的方法:(一).在Web.Config中创建连接字符串:1.<add name="ConnectionString" c ...
- 判断asp.net中session过期的方法
判断asp.net中session过期的方法 转载自:http://www.cnblogs.com/xilipu31/archive/2013/04/12/3016830.html 方法一:最麻烦也是 ...
- ASP.NET中几种加密方法
下面就是ASP.NET中几种加密方法.加密算法有两种,也就是上面提到的MD5和SHA1,这里我举的例子是以MD5为例,SHA1大致相同,只是使用的类不一样. MD5的全称是Message-Digest ...
随机推荐
- JS代码备忘
function $(v) { if (typeof v === 'function') { window.onload = v; } else if (typeof v === 'string') ...
- 《JS权威指南学习总结--7.8 数组方法》
内容要点: 一.join() Array.join()方法将数组中所有元素都转化为字符串并连接在一起,返回最后生产的字符串. 可以指定一个可选的字符串在生产的字符串中来分隔数组的各个元素.如果不指定分 ...
- 《JS权威指南学习总结--6.8对象的三个属性》
内容要点: 每一个对象都有与之相关的原型(prototype).类(class)和可扩展性 一.原型属性 1.对象的原型属性是用来继承属性的,这个属性是如此重要,以至于我们经常把 "0的原型 ...
- PAT 团体程序设计天梯赛-练习集 L1-003. 个位数统计
给定一个k位整数N = dk-1*10k-1 + ... + d1*101 + d0 (0<=di<=9, i=0,...,k-1, dk-1>0),请编写程序统计每种不同的个位数字 ...
- about hibernate lazy load and solution
about hibernate lazy load is that used when loaded again.it can increase efficienty and sava memory. ...
- 戏说HTML5(转)
如果有非技术人员问你,HTML5是什么,你会怎么回答? 新的HTML规范... 给浏览器提供了牛逼能力,干以前不能干的事...(确切地说应该是给浏览器规定了许多新的接口标准,要求浏览器实现牛逼的功能. ...
- hdu_2296_Ring(AC自动机+DP)
题目链接:hdu_2296_Ring 题意: 有m个字符串,每个字符串有一个价值,现在让你组成一个不超过n长度的字符串,使得价值最大 题解: 很明显是在AC自动机上的DP,设dp[i][j]表示当前长 ...
- 3种日志类型,微信付款反馈-->写入txt日志
--> 接收 $GLOBALS["HTTP_RAW_POST_DATA"] ---->xml 反系列化$qr = XML_unserialize( $rowpost ...
- openwrt源码下载地址(镜像)
与openwrt.org的源码svn路径仅仅多了一个.cn svn://svn.openwrt.org.cn/openwrt/branches/backfiresvn://svn.openwrt.or ...
- Worker+MQ解惑
用Worker来保证数据的一致性,再加上MQ来便于水平扩展,也提升了Worker的效率.这就是传说中的Worker+MQ,又叫做可靠消息方式.另外,将任务的查询和执行分工,形成父子任务,达到真正的分布 ...