473,397 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

loading user controls dynamically

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



Nov 18 '05 #1
1 995
"Nick Stansbury" <ni**************@sage-partners.com> wrote in message
news:eJ*************@tk2msftngp13.phx.gbl...
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
Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John | last post by:
Hi all, I'm having a little problem understanding the concepts of dynamically loading/unloading user conrols: 1. If I have a couple of usercontrols embedded within a few tables cells on my...
1
by: kanones | last post by:
Hi - I am seeing some performance degradation when I am loading a control dynamically onto a page with multiple other dynamical controls using Page.LoadControl versus dragging and dropping it...
2
by: Dave A | last post by:
I just don't get this... If I need to dynamically load controls into a web page I simply need to go PlaceHolder1.Controls.Add(new Button()); or similar. However when I need to dynamically...
2
by: nemesis.saurabh | last post by:
hi, Can we dynamically load a user control in the web form. problem i am facing is i have 2 user controls: uc1 and uc2. when my page is loading the functions and variables in the uc1 is...
1
by: Bob Rock | last post by:
Hello, I'm new to ASP.NET and I've been looking into the topic of dynamically loading (typically accomplished with a LoadControl followed by a MyControl.Controls.Add()) both user controls and...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.