How to: Pass Values Between ASP.NET Web Pages

1. Use a query string, which appends information onto the URL of the target page. You can use a query string when using a HyperLink control to build navigation into a page or when you are programmatically redirecting to another page using the Redirect method.

2.Use session state to store information that is then accessible to all ASP.NET Web pages in the current application. However, this takes server memory, and the information is stored until the session expires, which can be more overhead than you want for simply passing information to the next page. For details, see ASP.NET State Management Overview.

3.On the target page, read control values and public property values directly out of the source page. This strategy works in two situations: when the source page cross-posts to the target page (for more information, see How to: Post ASP.NET Web Pages to a Different Page), and when you call the Transfer method to transfer execution from the source to the target page on the server. The strategy of reading values directly from the source page is described in this topic.

public String CurrentCity
{
    get
    {
        return textCity.Text;
    }
}
<%@ PreviousPageType VirtualPath="~/SourcePage.aspx" %> 
Label1.Text = PreviousPage.CurrentCity


-------------------------------------------------------------------
if (Page.PreviousPage != null)
{
    TextBox SourceTextBox = 
        (TextBox)Page.PreviousPage.FindControl("TextBox1");
    if (SourceTextBox != null)
    {
        Label1.Text = SourceTextBox.Text;
    }
}

4. cookie

5. web cache

6.

 

posted @ 2015-05-29 13:30  Cathy Lee  阅读(162)  评论(0编辑  收藏  举报