By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,870 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,870 IT Pros & Developers. It's quick & easy.

Inheritance / Webform / IDE problem

P: n/a
I am having a problem with inheritance for my web solution.

Here are the steps I took for a project within C#:

-I first created a new class, descended from System.Web.UI.Page. For
this description, let's call this class "MyBasePage". Every webform
page within my solution will descend from this class instead of
System.Web.UI.Page. The reason for this is so that I have a common
base class from which I can put custom validation, formatting, and
messaging functionality for all of my pages. This base class does not
have a corresponding .aspx page since each page will be formatted
differently.

-Within that class, I declare a System.Web.UI.WebControls.Label
variable named "Msg". The purpose of this object is to have a common
place to give messages to the user, either in a header or footer of
the page.

-When I create a new WebForm, I change the inheritance to be from
MyBasePage instead of System.Web.UI.Page. I place a Label on the
..aspx templace on each new form and call it "Msg". The Msg object,
although placed within the .aspx page, is not declared within the .cs
file since it is declared in the base class. Everything works fine
and compiles.

Now this is where things go wrong::

If I switch from the HTML view to the designer for the .aspx page of
any of my descendant web pages, the IDE automatically adds the Msg
object to the list of declared page variables within the .cs file.
This, in turn, throws a warning during compilation and run-time errors
when the Msg object is accessed in code.

As long as I remove the declaration within the .cs file and recompile,
it all works. However, every time I switch to the page designer, it
replaces the declaration. It appears that the IDE does not verify
inheritance and existance of inherited webform objects before filling
them into the .cs file. Bug? Or am I doing things incorrectly?
TIA
Nov 15 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.