SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Sep 2010
    Posts
    131
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Session displayed in a aspx page

    In ASP.net 4.0 I have a webpage say page1.aspx.

    In this page I want to add a Session("sessionval") to an

    <a href="http://www.mysite.com/page2.aspx><???Session("sessionval")???></a>

    so that the value of Session("sessionval") will show and be underlined an when clicked go to the link.

    Is this possible?

  2. #2
    SitePoint Mentor NightStalker-DNS's Avatar
    Join Date
    Jul 2004
    Location
    Cape Town, South Africa
    Posts
    2,878
    Mentioned
    47 Post(s)
    Tagged
    0 Thread(s)
    Yes, that is possible, but would probably be better to do it from code behind. You can do something like this:
    <a href="http://www.mysite.com/page2.aspx" id="hrefSession" runat="server"></a>

    Then from code behind:
    hrefSession.InnerHTML = Session["sessionval"].ToString();

    or you can use .InnerText if it is only text. It is better to do it from code behind as you can easily wrap it in an if to check if session is not null before setting it and hiding it if it is.

    But if you really want to do it from the page and not code behind, you can do this:
    <a href="http://www.mysite.com/page2.aspx><%=Session("sessionval").ToString()%></a>

    I hope this helps


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •