Memi.Reflection

Private members of memi's thoughts

YAVSDB

(Which stands for Yet Another Visual Studio Designer Bug)

Try this:

1. Create a new ASP.NET application

2. Create a new class which inherits from Page. Call it, for example, MyPage.

3. Declare the following class level variable:

Protected WithEvents MyHidden As System.Web.UI.HtmlControls.HtmlInputHidden

(or any other web control of your choice, such as textbox, listbox and so on)

4. Create a new webform, and switch to the code behind file.

5. Change the ancestor page name to be “MyPage“, or whatever you named the class.

6. Switch to HTML view, and add the following HTML tag:

<input type=”hidden” runat=”server” id=”MyHidden”>

7. Compile the project.

Now, if you switch to the Designer mode of the .aspx page, you'll see it added a declaration for this field in the code behind file of the webform, which will result in immediately an error, since the control already exist in the ancestor page.

This is a really strange behavior, since if you'll delete the problematic line from the code behind, you'll be able to define events for it, which is understandable because it exists in the parent. It looks like the designer, when translating the content of the aspx to the code behind file, does not check whether there is already a definition for the controls in the class chain.

This bug gave me some real hard times. The only workaround I found was to add the control in runtime, which is much less elegant, and when I throw in the “designer can't show page inherited from abstract page class” bug, then creating a really extensible and dynamic base page framework become much harder and less elegant than it should.

Did you also encounter this behavior? Did you find a better solution than mine? If so - please let me know!

Posted: Feb 26 2004, 01:59 PM by memi | with 1 comment(s)
Filed under:

Comments

Paul Wilson said:

I can't really help on your main issue, but the “designer can't show page inherited from abstract page class” bug is resolvable since its not a bug at all. You simply need to make sure that anytime you refer to something that depends on a context existing, like a querystring, cookie, session, or viewstate, that's in your constructor or public property -- make sure you enclose such things in an if block that first checks if the context is not null. The designer must instantiate your base page and access its public properties, and having any code in them that assumes a runtime context will lead to what you see as a bug.
# February 26, 2004 9:26 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)