Blog

Get the referring page on Page_Load event in ASP.NET

When a page loads, in order to get the name of the page that sent you there, all you need to use is:

Request.UrlReferrer.ToString();

You can create a global variable to hold it:

string sReferrer = "";

Then, in the Page_Load event, assign it:

if (!Page.IsPostback)
{
    sReferrer = Request.UrlReferrer.ToString();
}

Or, you can put it in ViewState at that time:

if (!Page.IsPostback)
{
    ViewState("Referrer") = Request.UrlReferrer.ToString();
}

From there, on out, within that page, you can use either the variable, or ViewState, within that page as a link, or whatever you need it for.


Share this post



Leave a comment


Previous Post

Next Post


\