Link to home
Start Free TrialLog in
Avatar of vicomin
vicominFlag for United States of America

asked on

get referring page name

i need to just get the referring page name only and nothing else. then set the focus on a page control.
if (!Page.IsPostBack)
        {
            string MyReferrer = Request.ServerVariables["HTTP_REFERER"];
            if (MyReferrer == "udata.aspx" )
            {
                txtbxSearchSerialNumber.Focus();
            }
            //Response.Write(MyReferrer); //http://localhost:3627/FTs/udata.aspx?fti=4
        }

Open in new window

Avatar of tonig123
tonig123

in ASP.NET
here is the code for the referrer only :)
Dim referrer As String

referrer = Request.Urlreferrer.AbsolutePath.ToString

Response.Write(referrer)

Open in new window

Avatar of vicomin

ASKER

yeah got that - just need to figure out how to get the file name only
You may extract it to get the last segment for the page name, for example:

string refPageName = Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];
Avatar of vicomin

ASKER

Request.UrlReferrer.Segments[Request.UrlReferrer.Segments.Length - 1];

errors with:

Object reference not set to an instance of an object.
ASKER CERTIFIED SOLUTION
Avatar of intlaqa
intlaqa
Flag of Egypt image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial