Hi Geo,
Thanks for posting in the community!
From your description, you have a custom ASP.NET UserControl(ascx) and you
used it in a certain web page. You tried both using "new" constrcutor and
the LoadControl( ascx file) to create a new control and found that the
"new" constructor not worked. So you're wondering what''re the differences
bewteen the two means,yes?
As for this question, here are my suggestions on it:
The ASP.NET UserControl is a kind of Template based controls which has its
own template (in the ascx file), something like the include file in the
classic asp. When using it in a certain container page. The ASP.NET runtime
will first compile and generate the UserControl's class instance from the
ascx source template. So generally, there're two means to add a ascx
UserControl into a page:'
1. Statically add it onto page via add UserControl's declaration and tag.
2. Using LoadControl to dynamically load a UserControl instance from an
ascx file.
If you use "new" constructor to create a certain UserControl class
instance, it doesn't load the control's source content from the ascx
template, so it is not actually a complete UserControl instance. I think
you should still use the LoadControl method and then set the certain
properties of the controls before adding it to page.
If you'd like to use "new" constructor to create a certain control instance
like asp.net TextBox or Label, you need to develop a ASP.NET
WebServerControl which is quite different from UserControl.
Here are some tech reference on ASP.NET UserControl and WebSErver Control
in MSDN:
#Web Forms User Controls
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwebformsusercontro
ls.asp?frame=true
#Composite Control vs. User Control
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconcompositecontrolvsusercontrol.asp
#ASP.NET Server Control Development Basics
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconwebformscontroldev
elopmentbasics.asp?frame=true
Hope these help.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx