I have a link on page 1 if clicked take u to page 2

and page 2 if u click okay it should take u back to page

but when I use this on page 2 to:

ViewState["back"] = Request.UrlReferrer;

it returns null,

how do I fix this

on page 1:

link_Click(Obj sender, EventArgs e)
{
Response.Redirect("page2.aspx?ID" + row.cells[10].text)
}

You need to to get the Request.UrlReferrer if(!IsPostBack) in the Page_Load event and store it in the viewstate if your page perform postbacks.

Sometimes the Request.UrlReferrer is null if you are using AJAX to call Response.Redirect.

The UrlReferrer is based on the value of HTTP_REFERER header that a browser should send. Sometimes internet anti virus programs such as Norton's Internet Security will strip the header. Therefore the Request.UrlReferrer will be empty.

Instead of believing the Request.UrlReferrer, send the current page name as query string to the other page. In the target page, store the value of the query string in ViewState.

Refer these links.
http://stackoverflow.com/questions/149130/request-urlreferrer-null
http://stackoverflow.com/questions/1258324/should-request-urlreferrer-be-null-in-pageload-when-the-page-came-from-another-s
http://forums.asp.net/t/1101617.aspx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.