The new cross page postback feature released with ASP.Net 2.0 gave a new property on Page object called PreviousPage which provided access to the source or parent page.



For this we need to design the source page specifically for sharing information with target pages, and both pages are ASP.NET Web pages in the same Web application.

We can add public properties in the source page that expose information We want to share between pages. We can then read the values of the properties in the target pages.

This strategy works in two situations :

When the source page cross-posts to the target page.

When we call the Transfer method to transfer execution from the source to the target page on the server.

Follow the below process

In Source Page:

Just write a publi method whcich returns some string/int/flaot.... item in your

sourcepage.aspx.cs like as below.


public partial class SourcePage : System.Web.UI.Page
{
    public string GetTextBoxValue
    {
        get
        {
            return txtValue.Text;
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void btn_Click(object sender, EventArgs e)
    {      
       Response.Redirect("Destination.aspx");
    }
}

Now write the following code in your destinationpage.aspx to call the

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="destinationpage.aspx.cs" Inherits="destinationpage" %>

<%@ PreviousPageType VirtualPath="sourcepage.aspx" %>

In destinationpage.aspx.cs:

protected void Page_Load(object sender, EventArgs e)
    {      
        Label1.Text = PreviousPage.GetTextBoxValue;
    }

In this way we can pass values using the property on the page Object "PreviousPage"


Share it

1 comments:

Post a Comment