跨页面传送


KEY:PostBackUrl,PreviousPage.FindControl


Page1.aspx
<% @ Page Language="C#" AutoEventWireup="true"  %>
< script  runat ="server" >
    protected 
void Button1_Click(object sender, EventArgs e)
    
{
        Response.Write(
this.TextBox1.Text);
        Response.Write(
this.Calendar1.SelectedDate.ToString());
    }

</ script >
< body >
    
< form  id ="form1"  runat ="server" >
    
< div >
        
< asp:TextBox  ID ="TextBox1"  runat ="server" ></ asp:TextBox >
        
< asp:Calendar  ID ="Calendar1"  runat ="server" ></ asp:Calendar >
    
    
</ div >
        
< asp:Button  ID ="Button1"  runat ="server"  Text ="submit to itself"  OnClick ="Button1_Click"   />
        
< asp:Button  ID ="Button2"  runat ="server"  Text ="submit to page2"   PostBackUrl ="~/page2.aspx"   />
    
</ form >
</ body >
</ html >
Page2.aspx
<% @ Page Language="C#" AutoEventWireup="true" %>
<script runat="server">
    protected void page_load(Object sender,EventArgs e)
     {
        TextBox tb;
        Calendar cl;
        tb = Page.PreviousPage.FindControl("TextBox1") as TextBox;
        Response.Write(tb.Text);
    }
    
</script>
<body>
    <form id="form1" runat="server">
    <div>
    
    </div>
    </form>
</body>
</html>

你可能感兴趣的:(页面)