Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > loading user controls dynamically

Reply
Thread Tools

loading user controls dynamically

 
 
Nick Stansbury
Guest
Posts: n/a
 
      07-19-2004
Hi,
Apologies for what are probably pretty basic questions - and my convoluted
explanation. Built some simple user controls, that represent the UI side for
a whole bunch of Event objects (in the form of real everyday events likes
conferences, seminars etc.). So I have the following:

Class EventBase
EventTitle as string
etc.
End Class
Class EventSummary : Inherits EventBase
EventDate as dataTime
etc.
End Class
class EventDetails : Inherits EventBase
LongDescription as string
End class

And user controls CtlEventSummary.ascx & CtlEventDetail.ascx , each of
which have a BoundEvent as EventBase property and a BindEventDetails Method.
Seemed like a great idea, until I ran into some pretty simple problems:

I tried to go (summary):

For each CurrentEvent as EventBase in Session("CurrentEventList") 'stored
list of events to be displayed
'for a summary object
CurrentControl = new CtlEventSummary
CurrentControl.EventTitle = CurrentEvent.EventTitle
'etc.
PlaceHolderEventList.Controls.Add(CurrentControl)
CurrentControl.BindEventDetails() 'which basically does this :
Me.LblEventTitle = Me.EventTitle
'...
next

But I am getting an object not set error - because the Labels in the custom
control haven't been initialised yet. I could use the LoadControl() method -
but I don't really understand what it does or what I should have to use it.

In addition can someone help me out with how I deal with @Register
directives when I am using code-behind for all pages? If I end up having to
use LoadControl() how do I register the user control on the .vb page? Do I
need to?

Many thanks

Nick Stansbury







 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      07-19-2004
"Nick Stansbury" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> Apologies for what are probably pretty basic questions - and my

convoluted
> explanation. Built some simple user controls, that represent the UI side

for
> a whole bunch of Event objects (in the form of real everyday events likes
> conferences, seminars etc.). So I have the following:
>
> Class EventBase
> EventTitle as string
> etc.
> End Class
> Class EventSummary : Inherits EventBase
> EventDate as dataTime
> etc.
> End Class
> class EventDetails : Inherits EventBase
> LongDescription as string
> End class
>
> And user controls CtlEventSummary.ascx & CtlEventDetail.ascx , each of
> which have a BoundEvent as EventBase property and a BindEventDetails

Method.
> Seemed like a great idea, until I ran into some pretty simple problems:
>
> I tried to go (summary):
>
> For each CurrentEvent as EventBase in Session("CurrentEventList") 'stored
> list of events to be displayed
> 'for a summary object
> CurrentControl = new CtlEventSummary
> CurrentControl.EventTitle = CurrentEvent.EventTitle
> 'etc.
> PlaceHolderEventList.Controls.Add(CurrentControl)
> CurrentControl.BindEventDetails() 'which basically does this :
> Me.LblEventTitle = Me.EventTitle
> '...
> next


You need to use LoadControl to load a user control. This is because the HTML
in the user control needs to be compiled. In particular, "CtlEventSummary"
is just the codebehind. There is a generated class, something like
ASP._CtlEventSummary, which inherits from CtlEventSummary, and which is only
created when the user control is compiled. LoadControl will ensure that this
happens.
--
John Saunders
johnwsaundersiii at hotmail


 
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
Issues in ASP.NET 2.0 when dynamically loading user controls or asp.net web controls??? Bob Rock ASP .Net 1 09-17-2006 01:49 PM
Dynamically Loaded controls loading other controls =?Utf-8?B?V291dGVy?= ASP .Net 3 02-27-2006 07:25 PM
Dynamically loading user controls Johnny Fugazzi ASP .Net 0 11-24-2004 04:38 PM
when loading user controls dynamically, problem on postback sonic_soul ASP .Net 0 08-14-2003 10:05 PM
Re: Loading/Unloading web user controls dynamically in code - Does this look right? Ben Miller [msft] ASP .Net 0 08-05-2003 05:57 AM



Advertisments