locked
Session in asp RRS feed

  • Question

  • User643189141 posted

    Hi,

    How to call Session variable in asp?

    I tried this code:

    <a class="nomalwhite" href="showbet.aspx?dbid=<%# Eval("DBID")%>&lid=<%= Session("EventID") %>" >+ <%# Eval("totalbet") %></a>

    but writes:

    Compilation Error

    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'Session' does not exist in the current context

    Source Error:

    Line 461:</div>
    Line 462:<div id="totalbet" style="float:right; margin-right:5px;" >
    Line 463: <a class="nomalwhite" href="showbet.aspx?dbid=<%# Eval("DBID")%>&lid=<%= Session("EventID") %>" >+ <%# Eval("totalbet") %></a></div> Line 464:
    Line 465:    </ItemTemplate>


    Source File: c:\Sportsbook\sportsbook.aspx Line: 463

    Tuesday, July 5, 2011 12:33 PM

All replies

  • User-2010311731 posted

    Because you are in a databinding situation, try using <%# Session("EventID") %> instead.

     

    Matt

    Tuesday, July 5, 2011 12:41 PM
  • User643189141 posted

    I tried: <a class="nomalwhite" href="showbet.aspx?dbid=<%# Eval("DBID")%>&lid=<%# Session("EventID") %>">+ <%# Eval("totalbet") %></a>

    Error:

    The name 'Session' does not exist in the current context

    Please help

    Tuesday, July 5, 2011 1:07 PM
  • User-366017857 posted

    Use this one

    <a class="nomalwhite" href="showbet.aspx?dbid=<%# Eval("DBID")%>&lid='<%= Session["EventID"] %>'" >+ <%# Eval("totalbet") %></a>

    Tuesday, July 19, 2011 6:51 AM
  • User1098660122 posted

    I think it's better to define a property in your code behinde that use the session for it's background .

    somthing like this ;

    public string EventID
    {
      gert
         {
            return Session["ID"].ToString();
         }
    }

    then you can use this property in your aspx page
    <%#EventID%>
    Tuesday, July 19, 2011 8:26 AM
  • User-1359474226 posted

    Hi

     Are you referrign the namespace System.Web.UI

    Session is under System.Web,UI.Page class.

    Thank You

    Tuesday, July 19, 2011 10:18 AM