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!