Inheritance / Webform / IDE problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bita-kookoo

    Inheritance / Webform / IDE problem

    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.P age. 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.P age. 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.W ebControls.Labe l
    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.P age. 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
Working...