Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Reading a Session Variable from a Dynamically created control

Reply
Thread Tools

Reading a Session Variable from a Dynamically created control

 
 
RSH
Guest
Posts: n/a
 
      07-26-2006

Hi,

I have a situation where I have a page built in .Net 1.1 that I have a
PlaceHolder in the Design. From the CodeBehind I am dynamically referencing
a user control.

This is a snippet from the the CodeBehind from that page:

Dim mc As MainContent = New MainContent <----User Created Control

Select Case Trim(Session("UserType"))

Case "Corp"

mc.DisplayContent = "TESTCO"

Case "Service Center"

mc.DisplayContent = "TESTSC"

End Select

PlaceHolder1.Controls.Add(mc)


The Control has a property called DisplayContent that accepts the ContentID
for that page. The code in the ascx file is simple...basically there is a
placeholder in the Design view, and in the codebehind Property I am calling
a function. That code looks like this:

Public Property DisplayContent() As String

Get

Return DisplayContent

End Get

Set(ByVal Value As String)

If Len(Trim(Session("UserType"))) > 0 Then

LoadContent(Value, Trim(Session("UserType")))

End If

End Set

End Property



The problem is that for some reason The "Session("UserType") = Nothing" when
I step through the code in the control which doesn't make any sense because
the session variable exists in the select statement on the aspx page that
calls the control.

How do I get the control to see the Session variables?

Thanks!

Ron


 
Reply With Quote
 
 
 
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      07-26-2006
How about:

LoadContent(Value, Trim(HttpContext.Current.Session("UserType")))

Peter


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




"RSH" wrote:

>
> Hi,
>
> I have a situation where I have a page built in .Net 1.1 that I have a
> PlaceHolder in the Design. From the CodeBehind I am dynamically referencing
> a user control.
>
> This is a snippet from the the CodeBehind from that page:
>
> Dim mc As MainContent = New MainContent <----User Created Control
>
> Select Case Trim(Session("UserType"))
>
> Case "Corp"
>
> mc.DisplayContent = "TESTCO"
>
> Case "Service Center"
>
> mc.DisplayContent = "TESTSC"
>
> End Select
>
> PlaceHolder1.Controls.Add(mc)
>
>
> The Control has a property called DisplayContent that accepts the ContentID
> for that page. The code in the ascx file is simple...basically there is a
> placeholder in the Design view, and in the codebehind Property I am calling
> a function. That code looks like this:
>
> Public Property DisplayContent() As String
>
> Get
>
> Return DisplayContent
>
> End Get
>
> Set(ByVal Value As String)
>
> If Len(Trim(Session("UserType"))) > 0 Then
>
> LoadContent(Value, Trim(Session("UserType")))
>
> End If
>
> End Set
>
> End Property
>
>
>
> The problem is that for some reason The "Session("UserType") = Nothing" when
> I step through the code in the control which doesn't make any sense because
> the session variable exists in the select statement on the aspx page that
> calls the control.
>
> How do I get the control to see the Session variables?
>
> Thanks!
>
> Ron
>
>
>

 
Reply With Quote
 
 
 
 
RSH
Guest
Posts: n/a
 
      07-26-2006
Thanks!

That did the trick...although i'm not sure why that worked?


"Peter Bromberg [C# MVP]" <> wrote in message
news:3D9F656C-A1ED-4829-A92B-...
> How about:
>
> LoadContent(Value, Trim(HttpContext.Current.Session("UserType")))
>
> Peter
>
>
> --
> Co-founder, Eggheadcafe.com developer portal:
> http://www.eggheadcafe.com
> UnBlog:
> http://petesbloggerama.blogspot.com
>
>
>
>
> "RSH" wrote:
>
>>
>> Hi,
>>
>> I have a situation where I have a page built in .Net 1.1 that I have a
>> PlaceHolder in the Design. From the CodeBehind I am dynamically
>> referencing
>> a user control.
>>
>> This is a snippet from the the CodeBehind from that page:
>>
>> Dim mc As MainContent = New MainContent <----User Created Control
>>
>> Select Case Trim(Session("UserType"))
>>
>> Case "Corp"
>>
>> mc.DisplayContent = "TESTCO"
>>
>> Case "Service Center"
>>
>> mc.DisplayContent = "TESTSC"
>>
>> End Select
>>
>> PlaceHolder1.Controls.Add(mc)
>>
>>
>> The Control has a property called DisplayContent that accepts the
>> ContentID
>> for that page. The code in the ascx file is simple...basically there is
>> a
>> placeholder in the Design view, and in the codebehind Property I am
>> calling
>> a function. That code looks like this:
>>
>> Public Property DisplayContent() As String
>>
>> Get
>>
>> Return DisplayContent
>>
>> End Get
>>
>> Set(ByVal Value As String)
>>
>> If Len(Trim(Session("UserType"))) > 0 Then
>>
>> LoadContent(Value, Trim(Session("UserType")))
>>
>> End If
>>
>> End Set
>>
>> End Property
>>
>>
>>
>> The problem is that for some reason The "Session("UserType") = Nothing"
>> when
>> I step through the code in the control which doesn't make any sense
>> because
>> the session variable exists in the select statement on the aspx page that
>> calls the control.
>>
>> How do I get the control to see the Session variables?
>>
>> Thanks!
>>
>> Ron
>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=
Guest
Posts: n/a
 
      07-26-2006
You are providing your control, which is a separate class, a reference to the
current HttpContext so it can access the page's Session object.
Cheers,
Peter

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




"RSH" wrote:

> Thanks!
>
> That did the trick...although i'm not sure why that worked?
>
>
> "Peter Bromberg [C# MVP]" <> wrote in message
> news:3D9F656C-A1ED-4829-A92B-...
> > How about:
> >
> > LoadContent(Value, Trim(HttpContext.Current.Session("UserType")))
> >
> > Peter
> >
> >
> > --
> > Co-founder, Eggheadcafe.com developer portal:
> > http://www.eggheadcafe.com
> > UnBlog:
> > http://petesbloggerama.blogspot.com
> >
> >
> >
> >
> > "RSH" wrote:
> >
> >>
> >> Hi,
> >>
> >> I have a situation where I have a page built in .Net 1.1 that I have a
> >> PlaceHolder in the Design. From the CodeBehind I am dynamically
> >> referencing
> >> a user control.
> >>
> >> This is a snippet from the the CodeBehind from that page:
> >>
> >> Dim mc As MainContent = New MainContent <----User Created Control
> >>
> >> Select Case Trim(Session("UserType"))
> >>
> >> Case "Corp"
> >>
> >> mc.DisplayContent = "TESTCO"
> >>
> >> Case "Service Center"
> >>
> >> mc.DisplayContent = "TESTSC"
> >>
> >> End Select
> >>
> >> PlaceHolder1.Controls.Add(mc)
> >>
> >>
> >> The Control has a property called DisplayContent that accepts the
> >> ContentID
> >> for that page. The code in the ascx file is simple...basically there is
> >> a
> >> placeholder in the Design view, and in the codebehind Property I am
> >> calling
> >> a function. That code looks like this:
> >>
> >> Public Property DisplayContent() As String
> >>
> >> Get
> >>
> >> Return DisplayContent
> >>
> >> End Get
> >>
> >> Set(ByVal Value As String)
> >>
> >> If Len(Trim(Session("UserType"))) > 0 Then
> >>
> >> LoadContent(Value, Trim(Session("UserType")))
> >>
> >> End If
> >>
> >> End Set
> >>
> >> End Property
> >>
> >>
> >>
> >> The problem is that for some reason The "Session("UserType") = Nothing"
> >> when
> >> I step through the code in the control which doesn't make any sense
> >> because
> >> the session variable exists in the select statement on the aspx page that
> >> calls the control.
> >>
> >> How do I get the control to see the Session variables?
> >>
> >> Thanks!
> >>
> >> Ron
> >>
> >>
> >>

>
>
>

 
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
Affecting a dynamically created drop down from another dynamically created drop down. msimmons ASP .Net 0 07-16-2009 03:17 PM
System Session Variable VS. Own-declared 'Session' Variable chowchho ASP .Net 7 03-28-2008 02:38 PM
Managing ViewState of a dynamically created Custom Composite Server Control -(where the original is also dynamically created) dickster ASP .Net Building Controls 0 12-08-2005 09:32 AM
dynamically created controls an session state Julia ASP .Net 0 07-10-2005 09:24 AM
Safari cannot created variable dynamically? nick Javascript 4 02-15-2005 06:44 PM



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