code-behind in user control

bungpeng

Well-known member
Joined
Sep 10, 2002
Messages
906
Location
Malaysia
How to access properties of "user control" in code-behind?

I notice that for web control, vs.net will automatic generate code like:

Protected WithEvents WelcomeMsg As System.Web.UI.WebControls.Label

But for "user control", there are not. So, how do we access those properties of this "user control"?:confused:
 
All depends. Does your usercontrol (.ascx file) inherit from a custom base class, or are the properties declared within the .ascx file itself? Also, how is the usercontrol being loaded, via LoadControl or with a Register directive?
 
No inherit from any class, and I load my user control with "register directive".

So, what different? and how to solve?
 
Ive never actually handled UserControls like that, so Ill look into it and get back to you. For now try adding the following line to the codebehind:

Code:
Protected WithEvents [i]ControlID[/i] As System.Web.UI.UserControl

I imagine thatll work unless youre attempting to access programmer defined properties.
 
[mshelp=ms-help://MS.VSCC/MS.MSDNVS/cpguide/html/cpconexposingpageletproperties.htm]This help document[/mshelp] explains the process of implementing programmer defined properties in a UserControl. It might not be exactly what you want, but thats how its done for the most part.
 
Back
Top