Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Efficiency of dynamically adding web user controls

Reply
Thread Tools

Efficiency of dynamically adding web user controls

 
 
MC D
Guest
Posts: n/a
 
      11-17-2003
When I dynamically add a control by doing something like

dim x as control = Page.LoadControl("myControl.ascx")

am I actually loading the control from disk??? I don't really understand why
I can't access the class for the user control directly... in other words
just say:

dim x as new myControl()

(which doesn't generate an error, but it wil not render the UI)

If I'm adding a control dozens of times on a page, is this very
in-efficient?

Thanks for any help!

-D


 
Reply With Quote
 
 
 
 
Steve C. Orr [MVP, MCSD]
Guest
Posts: n/a
 
      11-17-2003
You don't have to use LoadControl.
Your dim statement is working fine. You've simply forgotten to add the
control to the page.
For this you should use Page.Controls.Add
Here's more info:
http://msdn.microsoft.com/library/de...mmatically.asp

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com



"MC D" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> When I dynamically add a control by doing something like
>
> dim x as control = Page.LoadControl("myControl.ascx")
>
> am I actually loading the control from disk??? I don't really understand

why
> I can't access the class for the user control directly... in other words
> just say:
>
> dim x as new myControl()
>
> (which doesn't generate an error, but it wil not render the UI)
>
> If I'm adding a control dozens of times on a page, is this very
> in-efficient?
>
> Thanks for any help!
>
> -D
>
>



 
Reply With Quote
 
 
 
 
Marina
Guest
Posts: n/a
 
      11-17-2003
User controls bear some resemblence to include files. Of course they are
object oriented, much more flexible, etc.

There are many large systems that rely on include files, and those work ok -
so I would imagine user controls wouldn't be any worse.

"MC D" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> When I dynamically add a control by doing something like
>
> dim x as control = Page.LoadControl("myControl.ascx")
>
> am I actually loading the control from disk??? I don't really understand

why
> I can't access the class for the user control directly... in other words
> just say:
>
> dim x as new myControl()
>
> (which doesn't generate an error, but it wil not render the UI)
>
> If I'm adding a control dozens of times on a page, is this very
> in-efficient?
>
> Thanks for any help!
>
> -D
>
>



 
Reply With Quote
 
-=Chris=-
Guest
Posts: n/a
 
      11-18-2003
Do not forget that some user controls are not just classes, but also contain
html snippets in the actual ascx file. It is for the purpose of retreiving
both the class, and the html within the ascx file, that page.loadcontrol()
is used.

User Controls are most helpful when creating commonly used UI components.
If your user control has no associated html in the .ascx file, I'd recommend
creating a simple class or a server control instead.



I was minding my own business when MC D blurted out:

> When I dynamically add a control by doing something like
>
> dim x as control = Page.LoadControl("myControl.ascx")
>
> am I actually loading the control from disk??? I don't really understand

why
> I can't access the class for the user control directly... in other words
> just say:
>
> dim x as new myControl()
>
> (which doesn't generate an error, but it wil not render the UI)
>
> If I'm adding a control dozens of times on a page, is this very
> in-efficient?
>
> Thanks for any help!
>
> -D


--
Insert corny line here


 
Reply With Quote
 
Big D
Guest
Posts: n/a
 
      11-18-2003
Instantiating the class directly does not render the interface.

-D
"Steve C. Orr [MVP, MCSD]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You don't have to use LoadControl.
> Your dim statement is working fine. You've simply forgotten to add the
> control to the page.
> For this you should use Page.Controls.Add
> Here's more info:
>

http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconInstantiatingUserControlsProgrammatically.asp
>
> --
> I hope this helps,
> Steve C. Orr, MCSD, MVP
> http://Steve.Orr.net
> Hire top-notch developers at http://www.able-consulting.com
>
>
>
> "MC D" <(E-Mail Removed)> wrote in message
> news:%(E-Mail Removed)...
> > When I dynamically add a control by doing something like
> >
> > dim x as control = Page.LoadControl("myControl.ascx")
> >
> > am I actually loading the control from disk??? I don't really understand

> why
> > I can't access the class for the user control directly... in other words
> > just say:
> >
> > dim x as new myControl()
> >
> > (which doesn't generate an error, but it wil not render the UI)
> >
> > If I'm adding a control dozens of times on a page, is this very
> > in-efficient?
> >
> > Thanks for any help!
> >
> > -D
> >
> >

>
>



 
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
Tough Q on Dynamically adding cached User Controls Justin Dutoit ASP .Net 0 03-19-2008 12:46 AM
Dynamically adding user controls, and then setting custom properties on those instances? ASP .Net 6 12-23-2006 09:12 AM
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 adding in User Controls tshad ASP .Net 2 07-27-2006 06:19 PM
Dynamically adding Web User Controls to ASP page Jason ASP .Net 7 05-04-2006 07:27 PM



Advertisments