Aspx and hidden WebControl properties

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • rrutkowski@gmail.com

    #1

    Aspx and hidden WebControl properties

    Hi!

    I have the following situation

    public class Class1 : WebControl
    {
    public Class1()
    : base(HtmlTextWr iterTag.Div)
    {
    }

    public new virtual int? Width
    {
    get { return this.ViewState["Width"] as int?; }
    set { this.ViewState["Width"] = value; }
    }

    public new virtual int? Height
    {
    get { return this.ViewState["Height"] as int?; }
    set { this.ViewState["Height"] = value; }
    }

    protected override void RenderContents( HtmlTextWriter writer)
    {
    writer.Write("{ 0}x{1}", this.Width, this.Height);
    }
    }

    The Width and Height properties of the WebControl are hidden and their
    type is changed to a nullable int. Then I have a derived class:

    public class Class2:Class1
    {
    public override int? Width
    {
    get { return base.Width; }
    set { base.Width = value; }
    }
    }

    Now, in the aspx I have
    <test:Class2 Width="500" Height="100" runat="server" />

    I expect to get as a result: <div>500x100</div>
    But I keep getting: <div Height="100">50 0x<div(the Height property
    is never assigned a value)

    Why does aspx keep ignoring a previously hidden property if it is not
    overridden?

    I'm using the Visual Studio 2008 SP1 and .NET Framework 3.5 SP1. IIS 7
    on a Windows Server 2008.

    --
    Regards
    Rudy
Working...