Friday, January 15, 2010

Getting values of another page into a diff page by using Context

We can get the values from a previous page(e.g. PageOne.aspx) into a new page(e.g. PageTwo.aspx) by using Context.
To make use of Context the old page i.e. PageOne.aspx should use Server.Transfer("PageTwo.aspx") to navigate to PageTwo.aspx.

Codes to retrive values of PageOne.aspx in PageTwo.aspx

PageTwo.aspx

public class PageTwo : Page
    {
        public PageOne  RetriveVal;
       
        private void Page_Load(object sender, EventArgs e)
        {            
                this.RetriveVal= (PageOne) this.Context.Handler;

              
                Label1.Text=RetriveVal.GetVal();////GetVal() returns a string which is defined in PageOne.aspx.cs
         }
}

No comments:

Post a Comment