1、可以用该功能的控件button、linkbutton、imagebutton,就是在crosspost1.aspx页面点这些控件,会转到另个页面crosspost2.aspx,而且 crosspost2.aspx可以获取、操作crosspost2.aspx里的控件的属性值。
一、crosspost2.aspx代码:
<%...@ page language="C#" %>
<script runat="server">...
void Button2_Click(object sender, System.EventArgs e)
...{
Label1.Text = "Hi " + TextBox1.Text + " you selected: " + Calendar1.SelectedDate.ToShortDateString();
}
</script>
<html>
<body>
<form id="Form1" runat="server">
Enter Name:
<asp:textbox id="TextBox1" runat="server"></asp:textbox>
<asp:button id="Button1" runat="server" text="Postback to Another Page" PostBackUrl="~/crosspost2.aspx" />
<br />
<br />
Pick Date:
<br />
<br />
<asp:calendar id="Calendar1" runat="server" font-names="Verdana" font-size="
9pt
"
forecolor="Black" height="190px" width="350px" bordercolor="White" backcolor="White" BorderWidth="1px" NextPrevFormat="FullMonth">
<todaydaystyle backcolor="#CCCCCC">
</todaydaystyle>
<selecteddaystyle forecolor="White" backcolor="#333399">
</selecteddaystyle>
<dayheaderstyle font-size="
8pt
" font-bold="True">
</dayheaderstyle>
<titlestyle bordercolor="Black" backcolor="White" font-bold="True" BorderWidth="4px" Font-Size="
12pt
" ForeColor="#333399">
</titlestyle>
<nextprevstyle verticalalign="Bottom" Font-Bold="True" Font-Size="
8pt
" ForeColor="#333333">
</nextprevstyle>
<othermonthdaystyle forecolor="#999999">
</othermonthdaystyle>
</asp:calendar>
<br />
<br />
<asp:button id="Button2" runat="server" text="Postback to Same Page" onclick="Button2_Click" />
<br />
<br />
<asp:label id="Label1" runat="server" font-size="Large">
</asp:label>
<br />
<br />
<br />
</form>
</body>
</html>
二、crosspost2.aspx代码:
<%...@ page language="C#" %>
<script runat="server">...
void Page_Load(object sender, System.EventArgs e)
...{
TextBox textBox1 = (TextBox) PreviousPage.FindControl("TextBox1");
Calendar calendar1 = (Calendar) PreviousPage.FindControl("Calendar1");
this.Label1.Text = string.Format("Hi {0} you selected {1}", textBox1.Text, calendar1.SelectedDate.ToShortDateString());
}
</script>
<html>
<body>
<form id="Form1" runat="server">
<asp:label id="Label1" runat="server" font-size="X-Large"></asp:label>
</form>
</body>
</html>