跨网页公布(Cross-Page Posting)

CrossPageSource页面,最为关键的是给Button控件设置PostBackUrl属性

 1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CrossPageSource.aspx.cs" Inherits="CrossPagePosting.CrossPageSource" %>
 2 
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml">
 6 <head runat="server">
 7     <title></title>
 8 </head>
 9 <body>
10     <form id="form1" runat="server">
11     <div>
12     <table>
13        <tr>
14            <td><asp:Label ID="Label1" runat="server" Text="请输入姓名:"></asp:Label></td>
15            <td><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></td>
16            <td>
17                <asp:Button ID="Button1" runat="server" Text="确定" 
18             PostBackUrl="~/CrossPageTarget.aspx" /></td>
19        </tr>
20        </table>
21     </div>
22     </form>
23 </body>
24 </html>

CrossPageTarget页面

 1 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CrossPageTarget.aspx.cs" Inherits="CrossPagePosting.CrossPageTarget" %>
 2 
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml">
 6 <head runat="server">
 7     <title></title>
 8 </head>
 9 <body>
10     <form id="form1" runat="server">
11     <div>
12        <table><tr><td>
13            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
14        </td></tr></table>
15     </div>
16     </form>
17 </body>
18 </html>

CrossPageTarget后台

 1 using System;
 2 using System.Collections.Generic;
 3 
 4 using System.Web;
 5 using System.Web.UI;
 6 using System.Web.UI.WebControls;
 7 
 8 namespace CrossPagePosting
 9 {
10     public partial class CrossPageTarget : System.Web.UI.Page
11     {
12         protected void Page_Load(object sender, EventArgs e)
13         {
14             TextBox txtUsername = (TextBox)PreviousPage.FindControl("TextBox1");
15             //txtUsername.
16             Label1.Text = "您输入的姓名是:" + txtUsername.Text;
17         }
18     }
19 }

 

posted @ 2012-12-10 14:40  FiberHomer  阅读(240)  评论(0编辑  收藏  举报