Monday, September 1, 2008

How to 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:


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.

Hire Me

Follow me on Facebook

Follow me

Do you find this Blog helpful?

Follow by Email

About Me

My Photo
Expert Senior Software Developer

Microsoft Business Card