Session Variables not available in UserControl

Discussion in 'ASP .Net' started by Lee Moore, Feb 2, 2006.

  1. Lee Moore

    Lee Moore Guest

    I have some user controls defined that represent a common header and footer
    for a particular site. the footer contains links with querystring parameters
    based on session variables. The problem is, I cannot access the session
    variables within my user control. The user controls work perfectly
    otherwise. Example code included.
     
    Lee Moore, Feb 2, 2006
    #1
    1. Advertising

  2. Lee Moore

    Lee Moore Guest

    To follow up. Here is the example from my footer. Like I said, the
    usercontrol works fine, but the session variables are empty.


    <%@ Control Language="VB" EnableViewState="False" %>
    </td>
    </tr>
    </table>
    <img src="images/index_01.jpg" width=100% height=6><br>
    <table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0">
    <tr>
    <td align="center">
    <%if Session("dept_id") = 0 then %>
    <a href="logon.aspx?ErrorCode=Session"><asp:Label runat="server"
    ForeColor="Blue" Font-Bold=True Font-Size="14px" ID="Home" Text="HOME"/></a>
    <%else%>
    <a href="dept_cycles.aspx?dept_id="<%=session("dept_id")%>"><asp:Label
    runat="server" ForeColor="Blue" Font-Bold=True Font-Size="14px" ID="Home2"
    Text="HOME"/></a>
    <%end if%>


    </td>
    <td align="center"><asp:Label runat="server" ForeColor="Blue"
    Font-Bold=True Font-Size="14px" ID="Plans" Text="PLANS"/></td>
    <td align="center"><asp:Label runat="server" ForeColor="Blue"
    Font-Bold=True Font-Size="14px" ID="Summ" Text="EXEC SUMMARY"/></td>
    <td align="center"><asp:Label runat="server" ForeColor="Blue"
    Font-Bold=True Font-Size="14px" ID="Fund" Text="FUNDING"/></td>
    <td align="center"><asp:Label runat="server" ForeColor="Blue"
    Font-Bold=True Font-Size="14px" ID="Goals" Text="GOALS"/></td>
    </tr>
    </table>
    </td>
    </tr>
    </TABLE>

    "Lee Moore" <> wrote in message
    news:...
    >I have some user controls defined that represent a common header and footer
    >for a particular site. the footer contains links with querystring
    >parameters based on session variables. The problem is, I cannot access the
    >session variables within my user control. The user controls work perfectly
    >otherwise. Example code included.
    >
    >
    >
     
    Lee Moore, Feb 2, 2006
    #2
    1. Advertising

  3. Lee,
    Try using:

    If Not HttpContext.Current.Session("dept_id") Is Nothing Then
    If HttpContext.Current.Session("dept_id") =0 then

    ' your cool code here

    End if
    End if


    if it still comes up empty, then most likely the Session item is null.
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Lee Moore" wrote:

    > To follow up. Here is the example from my footer. Like I said, the
    > usercontrol works fine, but the session variables are empty.
    >
    >
    > <%@ Control Language="VB" EnableViewState="False" %>
    > </td>
    > </tr>
    > </table>
    > <img src="images/index_01.jpg" width=100% height=6><br>
    > <table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0">
    > <tr>
    > <td align="center">
    > <%if Session("dept_id") = 0 then %>
    > <a href="logon.aspx?ErrorCode=Session"><asp:Label runat="server"
    > ForeColor="Blue" Font-Bold=True Font-Size="14px" ID="Home" Text="HOME"/></a>
    > <%else%>
    > <a href="dept_cycles.aspx?dept_id="<%=session("dept_id")%>"><asp:Label
    > runat="server" ForeColor="Blue" Font-Bold=True Font-Size="14px" ID="Home2"
    > Text="HOME"/></a>
    > <%end if%>
    >
    >
    > </td>
    > <td align="center"><asp:Label runat="server" ForeColor="Blue"
    > Font-Bold=True Font-Size="14px" ID="Plans" Text="PLANS"/></td>
    > <td align="center"><asp:Label runat="server" ForeColor="Blue"
    > Font-Bold=True Font-Size="14px" ID="Summ" Text="EXEC SUMMARY"/></td>
    > <td align="center"><asp:Label runat="server" ForeColor="Blue"
    > Font-Bold=True Font-Size="14px" ID="Fund" Text="FUNDING"/></td>
    > <td align="center"><asp:Label runat="server" ForeColor="Blue"
    > Font-Bold=True Font-Size="14px" ID="Goals" Text="GOALS"/></td>
    > </tr>
    > </table>
    > </td>
    > </tr>
    > </TABLE>
    >
    > "Lee Moore" <> wrote in message
    > news:...
    > >I have some user controls defined that represent a common header and footer
    > >for a particular site. the footer contains links with querystring
    > >parameters based on session variables. The problem is, I cannot access the
    > >session variables within my user control. The user controls work perfectly
    > >otherwise. Example code included.
    > >
    > >
    > >

    >
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Feb 2, 2006
    #3
  4. Lee Moore

    Lee Moore Guest

    No luck. Here is the exact code in use now...

    <%If HttpContext.Current.Session("dept_id") Is Nothing Then%>
    <a href="logon.aspx?ErrorCode=Session"><asp:Label runat="server"
    ForeColor="Blue" Font-Bold=True Font-Size="14px" ID="Home"
    Text="HOME"/></a>
    <%else%>
    <a
    href="dept_cycles.aspx?dept_id="<%=HttpContext.Current.Session("dept_id")%>"><asp:Label
    runat="server" ForeColor="Blue" Font-Bold=True
    Font-Size="14px" ID="Home2" Text="HOME"/></a>
    <%end if%>

    The link shows up as ...

    dept_cycles?dept_id=

    The code for the header of the page includes the code...

    <%if session("FullName") <> "" then
    response.write(session("FullName"))
    else
    response.write("Not Logged On")
    end if%>
    <br>
    Dept:
    <%if session("dept_name") <> "" then
    response.write(session("dept_name"))
    end if%>


    The header works fine. I cannot understand why the footer cannot access the
    values of session variables. Very Strange.


    Basically, if the session has expired, then I would like for the link to
    take them to the logon page
    "Peter Bromberg [C# MVP]" <> wrote in message
    news:...
    > Lee,
    > Try using:
    >
    > If Not HttpContext.Current.Session("dept_id") Is Nothing Then
    > If HttpContext.Current.Session("dept_id") =0 then
    >
    > ' your cool code here
    >
    > End if
    > End if
    >
    >
    > if it still comes up empty, then most likely the Session item is null.
    > Peter
    >
    > --
    > Co-founder, Eggheadcafe.com developer portal:
    > http://www.eggheadcafe.com
    > UnBlog:
    > http://petesbloggerama.blogspot.com
    >
    >
    >
    >
    > "Lee Moore" wrote:
    >
    >> To follow up. Here is the example from my footer. Like I said, the
    >> usercontrol works fine, but the session variables are empty.
    >>
    >>
    >> <%@ Control Language="VB" EnableViewState="False" %>
    >> </td>
    >> </tr>
    >> </table>
    >> <img src="images/index_01.jpg" width=100% height=6><br>
    >> <table border="0" width="100%" id="table1" cellspacing="0"
    >> cellpadding="0">
    >> <tr>
    >> <td align="center">
    >> <%if Session("dept_id") = 0 then %>
    >> <a href="logon.aspx?ErrorCode=Session"><asp:Label runat="server"
    >> ForeColor="Blue" Font-Bold=True Font-Size="14px" ID="Home"
    >> Text="HOME"/></a>
    >> <%else%>
    >> <a
    >> href="dept_cycles.aspx?dept_id="<%=session("dept_id")%>"><asp:Label
    >> runat="server" ForeColor="Blue" Font-Bold=True Font-Size="14px"
    >> ID="Home2"
    >> Text="HOME"/></a>
    >> <%end if%>
    >>
    >>
    >> </td>
    >> <td align="center"><asp:Label runat="server" ForeColor="Blue"
    >> Font-Bold=True Font-Size="14px" ID="Plans" Text="PLANS"/></td>
    >> <td align="center"><asp:Label runat="server" ForeColor="Blue"
    >> Font-Bold=True Font-Size="14px" ID="Summ" Text="EXEC SUMMARY"/></td>
    >> <td align="center"><asp:Label runat="server" ForeColor="Blue"
    >> Font-Bold=True Font-Size="14px" ID="Fund" Text="FUNDING"/></td>
    >> <td align="center"><asp:Label runat="server" ForeColor="Blue"
    >> Font-Bold=True Font-Size="14px" ID="Goals" Text="GOALS"/></td>
    >> </tr>
    >> </table>
    >> </td>
    >> </tr>
    >> </TABLE>
    >>
    >> "Lee Moore" <> wrote in message
    >> news:...
    >> >I have some user controls defined that represent a common header and
    >> >footer
    >> >for a particular site. the footer contains links with querystring
    >> >parameters based on session variables. The problem is, I cannot access
    >> >the
    >> >session variables within my user control. The user controls work
    >> >perfectly
    >> >otherwise. Example code included.
    >> >
    >> >
    >> >

    >>
    >>
    >>
     
    Lee Moore, Feb 3, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. huobazi
    Replies:
    1
    Views:
    692
    David Waz...
    Jul 3, 2003
  2. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    183
  3. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    187
    vatech1993
    Dec 11, 2004
  4. Event not firing in usercontrol inside usercontrol

    , Dec 10, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    156
  5. Kan Grewal

    Web Usercontrol in a Web Usercontrol not displaying...

    Kan Grewal, Jul 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    2
    Views:
    117
    Kan Grewal
    Jul 7, 2004
Loading...

Share This Page