Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Accessing user control
Message
From
10/03/2011 05:41:24
 
 
To
10/03/2011 05:00:26
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01502613
Message ID:
01503153
Views:
34
>>>>>Hi
>>>>>
>>>>>I've got some combo boxes in a user control and I want to access the contents in the code behind the page on which I have placed that control
>>>>>
>>>>>I get this message
>>>>>
>>>>>Error 1 'validation.ExportDateRangeSelectorfalse.Protected WithEvents radModels As Telerik.Web.UI.RadComboBox' is not accessible in this context because it is 'Protected'. D:\development\PsdGraphs\exportdata.aspx.vb 42 49
>>>>>
>>>>>how can I get access to the contents of the control
>>>>
>>>>You can probably sneak up on it using reflection. Something like:
var theProperty = (from p in  ObjectContainingradModels.GetType().GetProperties(BindingFlags.NonPublic|BindingFlags.Instance)
>>>>                                   .Where(x=>x.Name=="radModels") select p).FirstOrDefault();
>>>>       var theComboBox =  theProperty.GetValue(ObjectContainingradModels,null);
(C# I'm afraid)
>>>>UPDATE: Dunno why I was thinking Linq was useful. Simpler:
var theProperty = ObjectContainingradModels.GetType()
>>>>.GetProperty("radModels", BindingFlags.NonPublic | BindingFlags.Instance);
>>>
>>>I must be missing something here.
>>>
>>>If user control are useful why are they so hard to access from within the page.
>>
>>Not anything to do with UserControls per se. It's just that the property you are trying to access has been marked as 'protected' by the class designers so is not intended to be visible except to derived classes. You're using reflection to do something that they had not wanted you to do.....
>
>Right. Thanks Viv
>A lot to learn still is.

Hang on. Not easy to tell just from the error msg but is this a UserControl (containing a RadComboBox) that you created yourself?
If so you could just add a public property to the UserControl that exposes the combobox:
public RadComboBox theComboBox
        {
            get { return nameofComboBox; }
        }
Previous
Reply
Map
View

Click here to load this message in the networking platform