Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all

 

I am using the following code to get the name of the previous page that the user visited:

Private Function GetPreviousURL() As String

 

Dim script As String = Nothing

 

script &= "<script language=JavaScript id='previous'>" & vbCrLf

script &= "document.referrer;" & vbCrLf

script &= "</script>" & vbCrLf

 

'Verify script has not already been registered.

If Not ClientScript.IsStartupScriptRegistered("previous") Then

'Register the script.

ClientScript.RegisterStartupScript(Page.GetType, "previous", script)

End If

 

End Function

[code]

 

My only problem is that I am unsure as to how to get the value generated by document.referrer back to a vb.net variable. Any suggestions?

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

Request.UrlReferrer

 

There is no need to use client-side scripts for this. You can use just:

 

Private Function GetPreviousURL() As String
   Return Request.UrlReferrer
End Function

 

Good luck :cool:

Never trouble another for what you can do for yourself.
Posted
There is no need to use client-side scripts for this. You can use just:

 

Private Function GetPreviousURL() As String
   Return Request.UrlReferrer
End Function

 

Good luck :cool:

 

Thanks for the reply MrPaul.

 

Would love to be able to use that simple command, however, it appears not to work on all occasions. When I call it, it throws an exception, and all hell breaks loose.

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

Ok, the code:

Request.UrlReferrer.AbsoluteUri

works correctly, if I am moving from page A to B. The problem arises when I use the browser back button to go from page B back to A, or a button that I have added to the page that redirects the user back to page A. I have had a number of problems with the above command in that it does not always have a value, thus causing me problems.

 

Mike55.

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...