.net to parse url and get script value

Discussion in 'C#' started by LineOfSight, Apr 20, 2007.

  1. #1
    Can anyone suggest a way of doing the following.

    Within my navigation I have - widget1 (which links to widget1.aspx) widget2 (which links to widget2.aspx) widget3 (which links to widget3.aspx).

    If a user clicks the link 'widget2' and arrives at the widget2.aspx, I'm trying to get the script that will look at the URL string, stripout the last part i.e. widget2.aspx as a variable so that I can then say, if variable = widget2.aspx the display the link text but do not link it, otherwise, link it.

    Thanks
     
    LineOfSight, Apr 20, 2007 IP
  2. jimrthy

    jimrthy Guest

    Messages:
    283
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is this something similar to what you're wanting to do? I have a site with the navigation bar set up as a user control. Whatever the current page is, I just list it, without it being a link. Are you looking for something along those lines?
     
    jimrthy, Apr 21, 2007 IP
  3. webcosmo

    webcosmo Notable Member

    Messages:
    5,840
    Likes Received:
    153
    Best Answers:
    2
    Trophy Points:
    255
    #3
    Considering u r using asp .Net in C#:
    on aspx:
    ---------
    <asp:Label id="lbl" runat="server"/>

    on C#:
    -------
    if(Request.Url.ToLower().IndexOf("widget2.aspx")>=0)
    lbl.Text="<a href=widget2.aspx>Widget2</a>";
    else
    lbl.Text="Widget2";
     
    webcosmo, Apr 21, 2007 IP
  4. LineOfSight

    LineOfSight The Doctor

    Messages:
    125
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks Guys :)

    Webcosmo - that does the trick. Thats
     
    LineOfSight, Apr 22, 2007 IP
  5. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #5
    A neat trick with ASP.NET is you can declare your referer as a URI variable type, then it auto-parses out the parts for you :)... you can even URI. Parse or TryParse to cast it to a URI I believe...
     
    ccoonen, Apr 23, 2007 IP