Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Session Variables not available in UserControl

Reply
Thread Tools

Session Variables not available in UserControl

 
 
Lee Moore
Guest
Posts: n/a
 
      02-02-2006
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.



 
Reply With Quote
 
 
 
 
Lee Moore
Guest
Posts: n/a
 
      02-02-2006
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_i d")%>"><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.
>
>
>



 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      02-02-2006
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_i d")%>"><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.
> >
> >
> >

>
>
>

 
Reply With Quote
 
Lee Moore
Guest
Posts: n/a
 
      02-03-2006
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.Cur rent.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:A5045E14-5F64-4615-BF46-...
> 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_i d")%>"><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.
>> >
>> >
>> >

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 1 12-11-2004 01:28 PM
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 0 12-10-2004 02:21 PM
Event not firing in usercontrol inside usercontrol vatech1993@yahoo.com ASP .Net Building Controls 0 12-10-2004 02:20 PM
Web Usercontrol in a Web Usercontrol not displaying... Kan Grewal ASP .Net Web Controls 2 07-07-2004 08:12 AM
Use LoadControl to load a usercontrol but the webcontrol in the usercontrol can not AutoPostBack huobazi ASP .Net 1 07-03-2003 03:14 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57