How do I get Previous Page's URL?http://forums.asp.net/t/1097333.aspx/1?How+do+I+get+Previous+Page+s+URL+Tue, 01 Feb 2011 04:39:08 -050010973331659776http://forums.asp.net/p/1097333/1659776.aspx/1?How+do+I+get+Previous+Page+s+URL+How do I get Previous Page's URL? <p>I want to make a Return column visible on my GridView based on a condition, but I want the NavigateUrl to be the previouspage URL plus the ID that I am sending back to that page.</p> <p>Currently, I use this:<br> Dim previousPage As String = Page.Request.UrlReferrer.ToString</p> <p>This gives me the previous referral page's URL, BUT... if I hit Find to search for something and then the search lists to my GridView, previousPage errors with a Object Not Set to Instance, etc. Error. Why is this? And does anyone have a way of grabbing the previous page URL?</p> 2007-04-10T20:15:34-04:001660592http://forums.asp.net/p/1097333/1660592.aspx/1?Re+How+do+I+get+Previous+Page+s+URL+Re: How do I get Previous Page's URL? <p>If your page is stright away opened without any redirection from any other page&nbsp; Request.UrlReferrer will be null. So check whether it is null or not before using that code.</p> <font color="#0000ff" size="2"> <p>if</font><font size="2">(Request.UrlReferrer!=</font><font color="#0000ff" size="2">null</font><font size="2">)</p> <p>Response.Write(Request.UrlReferrer.ToString());</p> <p>Let me know if you need any further help</p> </font> 2007-04-11T09:58:54-04:002196263http://forums.asp.net/p/1097333/2196263.aspx/1?Re+How+do+I+get+Previous+Page+s+URL+Re: How do I get Previous Page's URL? <p>Hi,</p> <p>I tried with your code but its giving the same page url only, what should I do?</p> <p>I am running my application on localhost, so will be a reason to give the same url everytime (means only current page's url only) ????????</p> <p>After navigating three pages, my &quot;sendmail&quot; page is opening (Where I am fetching the previous page's url)</p> <p>Any ideas?</p> <p>&nbsp;</p> 2008-02-26T11:37:29-05:002197037http://forums.asp.net/p/1097333/2197037.aspx/1?Re+How+do+I+get+Previous+Page+s+URL+Re: How do I get Previous Page's URL? <p>string referer = Request.UrlReferrer.ToString();</p> <p>One thing to remember is that UrlReferrer will change to your pagename when you post back to the server.. so you should maybe store the value in ViewState on the first page load of the page if you are wanting to redirect the user to the previous page after a couple postbacks to the same page.<br> </p> <p>if( !IsPostBack )<br> {<br> &nbsp;ViewState[&quot;PreviousPageUrl&quot;] = Request.UrlReferrer.ToString();<br> }<br> <br> <strong>The situations where it does work include the following methods of a browser loading a URL:</strong> </p> <p>clicking on a straight HTML &lt;a href&gt; link;<br> submitting a form, using POST or GET, from a submit button, &lt;input type=image&gt; or client-side script (form.submit())</p> <p><strong>The situations where it doesn't work:</strong></p> <p>using Response.Redirect / Server.Transfer;<br> clicking on a Favorite, History, or the recently-typed URLs list;<br> clicking on 'Home' in IE's toolbar, or an item in IE's 'Links' toolbar;<br> using location.href or location.replace() in client-side JScript/JavaScript/VBScript;<br> using HierMenus (details);<br> typing the URL directly in the browser and hitting Enter or clicking 'Go';<br> launching a clickable URL from an e-mail or MS Office document;<br> using Response.AddHeader&nbsp; or &lt;meta http-equiv=refresh&gt; to redirect;<br> loading the URL with XML<br> </p> 2008-02-26T17:25:00-05:002200738http://forums.asp.net/p/1097333/2200738.aspx/1?Re+How+do+I+get+Previous+Page+s+URL+Re: How do I get Previous Page's URL? <p>Hi <strong>gopalanmani,</strong></p> <p>Great job !!!!!!! I got the answer but thank for giving such a good information about when it doesnt work.</p> <p>&nbsp;Thank you very much.</p> 2008-02-28T06:52:55-05:004132778http://forums.asp.net/p/1097333/4132778.aspx/1?Re+How+do+I+get+Previous+Page+s+URL+when+i+am+using+Response+Redirect+Re: How do I get Previous Page's URL when i am using Response.Redirect()? <p>How do I get Previous Page's URL when i am using Response.Redirect()?&nbsp;</p> 2010-10-20T10:51:43-04:004281586http://forums.asp.net/p/1097333/4281586.aspx/1?Re+How+do+I+get+Previous+Page+s+URL+when+i+am+using+Response+Redirect+Re: How do I get Previous Page's URL when i am using Response.Redirect()? <p>if(!IsPostback) </p> <p>{&nbsp; </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#0000ff; font-size:x-small"><span style="color:#0000ff; font-size:x-small"></p> <p>if(!<span style="color:#0000ff; font-size:x-small"><span style="color:#0000ff; font-size:x-small">string</span></span><span style="font-size:x-small">.IsNullOrEmpty(Request.UrlReferrer.ToString())</span></p> <p>{</p> </span> <p>sPreviousPageUrl = Request.UrlReferrer.ToString();</p> <p>}</p> <p>&nbsp;</p> <p>}</p> <p>&nbsp;</p> <p><span style="font-size:x-small"><span style="font-family:; font-size:x-small"><font size="2"></p> <p></font></p> </span> <p></p> </span> <p>&nbsp;</p> <p><span style="color:#0000ff; font-size:x-small"><span style="color:#0000ff; font-size:x-small">public</span></span><span style="font-size:x-small"> </span><span style="color:#0000ff; font-size:x-small"><span style="color:#0000ff; font-size:x-small">string</span></span><span style="font-size:x-small"> sPreviousPageUrl<span style="font-family:; font-size:x-small"> <font size="2"></p> <p>{</font></p> </span> <p></p> </span> <p></p> <p>&nbsp;</p> <p><span style="color:#0000ff; font-size:x-small"><span style="color:#0000ff; font-size:x-small">get</span></span><span style="font-size:x-small"> { </span><span style="color:#0000ff; font-size:x-small"><span style="color:#0000ff; font-size:x-small">return</span></span><span style="font-size:x-small"> (</span><span style="color:#0000ff; font-size:x-small"><span style="color:#0000ff; font-size:x-small">string</span></span><span style="font-size:x-small">)ViewState[</span><span style="color:#a31515; font-size:x-small"><span style="color:#a31515; font-size:x-small">&quot;sPreviousPageUrl&quot;</span></span><span style="font-size:x-small">]; }<span style="font-family:; font-size:x-small"> <font size="2"></p> <p></font></p> </span> <p></p> </span> <p></p> <p>&nbsp;</p> <p><span style="color:#0000ff; font-size:x-small"><span style="color:#0000ff; font-size:x-small">set</span></span><span style="font-size:x-small"> { ViewState[</span><span style="color:#a31515; font-size:x-small"><span style="color:#a31515; font-size:x-small">&quot;sPreviousPageUrl&quot;</span></span><span style="font-size:x-small">] = </span><span style="color:#0000ff; font-size:x-small"><span style="color:#0000ff; font-size:x-small">value</span></span><span style="font-size:x-small">; }</span></p> <p>}</p> <p>&nbsp;</p> <p><span style="font-size:x-small"></p> <p>Response.Redirect(sPreviousPageUrl);</p> </span> <p>&nbsp;</p> </span> <p></p> <p><span style="font-size:x-small"></span></p> <p></p> <p><span style="font-size:x-small"></span></p> <p>&nbsp;</p> <p></p> <p><span style="font-size:x-small"><span style="font-family:; font-size:x-small"><font size="2"></p> <p></font></p> </span> <p></p> </span> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p><span style="font-size:x-small"><span style="font-family:; font-size:x-small"><font size="2"></p> <p></font></p> </span> <p></p> </span> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;<span style="font-size:x-small"> </p> <p>&nbsp;</p> <p><span style="font-family:; font-size:x-small"><font size="2"></p> <p></font></p> </span> <p></p> <p></p> <p></p> </span> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> <p>&nbsp;</p> 2011-02-01T04:39:08-05:00