views:

21

answers:

2

Hi, I have a very simple setup, single mycontrol.ascx with assoicated mycontrol.ascx.designer.vb and mycontrol.ascx.vb file.

mycontrol.ascx embeds a single reference to a custom control: "MyMenu":

<mM:myMenu id="myMenu1" runat="server" />

This has created a protected reference in the mycontrol.ascx.designer.vb file:

Protected WithEvents myMenu1 As Global.CustomControls.MyMenu

Now, when I breakpoint the Page_Load() event of mycontrol.ascx, and inspect the members returned from the type via:

Me.GetType().GetMembers()

I cannot any reference to myMenu1. If I look at the control with intellisence, the property is accessible:

Me.myMenu1 

Can anyone explain exactly what I'm missing and what I need to do to access designer created properties at runtime through reflection?

Cheers

Yum.

A: 

Your .acsx file creates a separate class (generated by the compiler) that inherits the codebehind class.

GetMembers only returns the members defined directly on the class, not any members inherited from its base class.

You need to get the members defined on the base class, like this:

Me.GetType().BaseType.GetMembers()
SLaks
Okay, I've tried this but it still doesn't show the myMenu1 control that is defined in the mycontrol.ascx.designer.vb file.
Yumbelie
Try adding another `.BaseType`
SLaks
A: 

what I need to do to access designer created properties at runtime through reflection?

I don't know your menu control but you don't need to grasp the members of the user control, you need to get to the members of the menu control.

myMenu1.GetType().GetMembers()

Besides why use reflection? Doesn't your custom control expose properties with which you can set your settings like

myMenu1.SelectedMenuItem = 3
XIII
The problem I've illustrated is basically a distillation of actual issue I'm trying to resolve. In a nutshell, I've got an .ascx control that acts as a base, and needs to be derived into another .ascx. While this approach is simple with code behind: Inherits BaseMenuThe same does not apply to the markup defined in the .ascx file. From what I've read, there is no way to inherit the markup so you've got to copy it into the derived control's .ascx.
Yumbelie
I envisaged a possible solution by using Page.ParseControl to load the underlying BaseMenu.ascx and add it to myControl.ascx. Understandbly designer properties don't carry through because of the fact compilation has already occured, the control placeholders (myMenu1) from the derivation do not get 'glued' to the .ascx control instance. In effect, I wanted to use reflection to manually re-map the mycontrol.ascx.designer.vb properties to the .ascx control instances I'd loaded via ParseControl.
Yumbelie