Fog Creek Software
Discussion Board




Welcome! and rules

Joel on Software

Web User Control Filename Trick

Ever needed to look up the filename for a Web User Control? If your control is named "MyControl.ascx", then the following code inside of it:

    this.GetType().Name;

will return "MyControl_ascx". Not the excact filename, but close enough.

Thomas Eyde
Tuesday, August 19, 2003

Out of interest - why did you need to know the filename of the control?

Duncan Smart
Wednesday, August 20, 2003

I am developing a web app with dynamic menus, that is, the app's owner can add/remove any menu item at will.

I implement the different menus as web user controls, and I would like them to ask for their associated menu items.

I think this is neat:

    Menu[] menus = Menu.GetMenusForControl(this);

In this case I feel a config file is the better place to manage the relations:

    <menus>
        <menu id="1" name="left menu"
            controlName="left.ascx"/>
        <menu id="2" name="right menu"
            controlName="right.ascx"/>
    </menus>

Thomas Eyde
Wednesday, August 20, 2003

put an id on the control. then the user can add multiple controls, etc.

mb
Thursday, August 21, 2003

+1 for IDs. That's what they're for. :)

Brad Wilson (dotnetguy.techieswithcats.com)
Saturday, August 23, 2003

Yes, but those are hard coded

Thomas Eyde
Sunday, August 24, 2003

*  Recent Topics

*  Fog Creek Home