<%@ Page Language="C#" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> public String UserName { get { return this.txtName.Text; } } protected void Button1_Click(object sender, EventArgs e) { Label1.Text = "Postback from self. Your Name is: " + txtName.Text; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <meta content="text/JScript" http-equiv="content-script-type" /> <title>First Page</title> </head> <body> <form id="form1" runat="server"> <div> <h3>The Frist Page</h3> Your Name: <asp:TextBox ID="txtName" runat="server" /> <asp:Label ID="Label1" runat="server" EnableViewState="False" /><br /> <br /> <asp:Button ID="Button1" runat="server" Text="Postback to Same Page" OnClick="Button1_Click" /><br /> <br /> <asp:Button ID="Button2" runat="server" Text="Postback to Second Page" PostBackUrl="~/SecondPage.aspx" /><br /> </div> </form> </body> </html> |
<%@ Page Language="C#" %> <%@ PreviousPageType VirtualPath="~/FirstPage.aspx" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> protected void Page_Load(object sender, EventArgs e) { this.Label1.Text = "Your Name is : " + PreviousPage.UserName; } </script> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Second Page</title> </head> <body> <form id="form1" runat="server"> <div> <h1>This is the Second Page</h1> <p><asp:Label ID="Label1" runat="server"></asp:Label> </p> </div> </form> </body> </html> |
<form id="MainForm" Target="_blank" runat="server"> |
if (Page.PreviousPage != null) { TextBox txtName = (TextBox)Page.PreviousPage.FindControl("txtName"); if (txtName != null) { Label1.Text = txtName.Text; } } |
Panel MainPanel = (Panel)PreviousPage.FindControl("MainPanel"); if (MainPanel != null) { TextBox UserName = (TextBox)MainPanel.FindControl("UserName"); if (UserName != null) { Label1.Text = UserName.Text; } } else { Label1.Text = "Cannot find UserName control."; } |
<%@ PreviousPageType VirtualPath="~/FirstPage.aspx" %> |
SourcePage_aspx sourcePage; sourcePage = (SourcePage_aspx) PreviousPage; Label1.Text = sourcePage.UserName; |
if(PreviousPage != null) { if(PreviousPage.IsCrossPagePostBack == true) { Label1.Text = "跨页面提交"; } } else { Label1.Text = "非跨页面提交"; } |
属 性
|
跨页面提交
|
Server.Transfer
|
IsPostBack | false | false |
PreviousPage | 源页面的引用 | 源页面的引用 |
PreviousPage.IsCrossPagePostBack | true | false |
IsCrossPagePostBack | false | false |
IsCallBack | false | false |
<input type="submit" name="Button2" value="Postback to Second Page" onclick="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions("Button2", "", false, "", "SecondPage.aspx", false, false))" id="Button2" /> |
function WebForm_PostBackOptions(eventTarget, eventArgument, validation, validationGroup, actionUrl, trackFocus, clientSubmit) { this.eventTarget = eventTarget; this.eventArgument = eventArgument; this.validation = validation; this.validationGroup = validationGroup; this.actionUrl = actionUrl; this.trackFocus = trackFocus; this.clientSubmit = clientSubmit; } function WebForm_DoPostBackWithOptions(options) { var validationResult = true; if (options.validation) { if (typeof(Page_ClientValidate) == 'function') { validationResult = Page_ClientValidate(options.validationGroup); } } if (validationResult) { if ((typeof(options.actionUrl) != "undefined") && (options.actionUrl != null) && (options.actionUrl.length > 0)) { theForm.action = options.actionUrl; } if (options.trackFocus) { var lastFocus = theForm.elements["__LASTFOCUS"]; if ((typeof(lastFocus) != "undefined") && (lastFocus != null)) { if (typeof(document.activeElement) == "undefined") { lastFocus.value = options.eventTarget; } else { var active = document.activeElement; if ((typeof(active) != "undefined") && (active != null)) { if ((typeof(active.id) != "undefined") && (active.id != null) && (active.id.length > 0)) { lastFocus.value = active.id; } else if (typeof(active.name) != "undefined") { lastFocus.value = active.name; } } } } } } if (options.clientSubmit) { __doPostBack(options.eventTarget, options.eventArgument); } } |
<input type="hidden" name="__PREVIOUSPAGE" id="__PREVIOUSPAGE" value="ND3_1GqjDSUeAC3yLYVz-eQrkTzZLYFHliIFf7mMQVBdmwZmFi8HG4mzX5pfZY0n0" /> |