Cross page postback
来源:互联网 发布:php socket 长连接 编辑:程序博客网 时间:2024/05/01 01:31
Frame.htm
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
</head>
<frameset cols="50%,*">
<noframes>
<body>
you brownser do not support Frame!
</body>
</noframes>
<frame name="left" src="Left.aspx"/>
<frame name="right" src="Right.aspx" />
</frameset>
</html>
left.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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server" method="post" target="right">
<div>
<table>
<tr>
<td style="width: 84px">
Name1</td>
<td style="width: 228px">
<asp:TextBox ID="TextBox1" runat="server" Width="218px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 84px">
Name2</td>
<td style="width: 228px">
<asp:TextBox ID="TextBox2" runat="server" Width="219px"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 84px">
</td>
<td style="width: 228px; text-align: right">
<asp:Button ID="Button1" runat="server" Text="Button" /></td>
</tr>
</table>
</div>
</form>
</body>
</html>
right.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>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td style="width: 100px; height: 21px;">
Name1</td>
<td style="width: 177px; height: 21px;">
<asp:Label ID="Label1" runat="server" Text="Label" Width="185px"></asp:Label></td>
</tr>
<tr>
<td style="width: 100px">
Name2</td>
<td style="width: 177px">
<asp:Label ID="Label2" runat="server" Text="Label" Width="183px"></asp:Label></td>
</tr>
</table>
</div>
</form>
</body>
</html>
- [1] Page. PreviousPage.FindControl(id)
- [2] 在目标页加入PreviousPageType页面指令,并指定VirtualPath,这样可以把PreviewPage作为一个强类型的页面来访问,如:string name=PrevioursPage.Name
<%@ PreviousPageType VirtualPath="~/Tricks/Page1.aspx" %>
- [3] 在目标页加入PreviousPageType页面指令,指定TypeName,这样也可以把PreviewPage作为一个强类型的页面来访问,如:string name=PrevioursPage.Name(但这种情况下必须注意的是:PersonInfoPage 必须派生自System.Web.UI.Page)
<%@ PreviousPageType TypeName="PersonInfoPage" %>
Page1.aspx codebehind :
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Tricks_Page1 : System.Web.UI.Page
{
public string Name
{
get
{
return TextBox1.Text;
}
}
public string Age
{
get
{
return TextBox2.Text;
}
}
public bool IsMarried
{
get
{
return chkMarried.Checked;
}
}
}
Pag2.aspx code behind :
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class Tricks_Page3 : System.Web.UI.Page
...{
protected void Page_Load(object sender, EventArgs e)
...{
if (PreviousPage!=null)
...{
this.Label1.Text = PreviousPage.Name;
this.Label2.Text = PreviousPage.Age;
this.CheckBox1.Checked = PreviousPage.IsMarried;
this.CheckBox1.Enabled = false;
}
}
}
注意:Pag2.apsx是含有页面指令的
<%@ PreviousPageType VirtualPath="~/Tricks/Page1.aspx" %>
对于通过PreviousPageType 页面指令来访问,需要注意:
[1] 由于ASP.NET中的每个页面类所包含的子控件对应的是protected成员,所以您不能直接通过 PreviousPage引用来访问源页面中的控件,而先需要将源页面中需要被访问的属性公开出来。
[2]使用方法一的时候,若页面是包含有 Master页面的话,(即是一个Content Page ),下面的代码是无法拿到PreviousPage的Control (Data)的:
string str= Request.Form["txtData"]; //it does't work
TextBox t = (TextBox)PreviousPage.FindControl("txtData");正确的因该是:
string str = Request.Form["ctl00$ContentPlaceHolder1$txtData"]; //OK
TextBox t = (TextBox)PreviousPage.Form.FindControl("ContentPlaceHolder1").FindControl("txtData"); //OK
原因是由于ContentPage在render之前会把MasterPage和并(可以把MasterPage理解为ContentPage的一个Control),因此你的control id因该是:ctl00$ContentPlaceHolder1$id
[ctl00 is the form element, and contentPlaceHoder1 is the id of the contentPlaceHolder]这一点,我可以从页面Trace output的结果是很容易看出来的:
[3]如果要判断是否为跨页面提交,可以对目标页面的PreviousPage属性返回的引用页面的IsCrossPagePostBack属性进行判断。注意,如果当前页面不是跨页面提交的目标页面,则其PreviousPage属性为空
- Cross page postback
- Cross-Page Postback 拾遗
- .net 2.0 Cross-Page Postback的使用
- 错误日志——PreviousPage is null when attempting a cross-page postback using a button and the PostBack
- 使用Cross-Page Postback(跨页面提交)在页面间传递数据
- 使用Cross-Page Postback(跨页面提交)在页面间传递数据
- 使用Cross-Page Postback(跨页面提交)在页面间传递数据
- 使用Cross-Page Postback(跨页面提交)在页面间传递数据
- 使用Cross-Page Postback(跨页面提交)在页面间传递数据
- Page对象的PostBack属性
- Page Events: Order and PostBack
- The page is performing an async postback but the ScriptManager
- asp.net 2.0中的Cross PAGE REQUEST
- cross-page posting in ASP.NET 2.0
- Cross page posting in ASP.NET 2.0
- 跨网页公布(Cross.Page Postiing)
- 跨网页公布(Cross.Page Postiing) --续
- asp.net 2.0中的Cross PAGE REQUEST
- 如何写出专业的C头文件(转)
- 程序人生
- 你或许还未听说过的一些ASP.NET 2.0要诀
- Component Titled Border
- Ajax原理详细说明
- Cross page postback
- 自己动手写操作系统--"Hello, OS world!"
- MSN 登录时出现80048820错误的官方解释
- AJAX经典文章(部分为中文版)
- Exif 属性
- ANT的安装/配置笔记
- Java程序性能之二
- Linux开发程序导引
- 金额转换,阿拉伯数字的金额转换成中国传统的形式如:(¥1011)->(一千零一拾一元整)输出