Aspx and hidden WebControl properties

Discussion in 'ASP .Net' started by rrutkowski@gmail.com, Sep 25, 2008.

  1. Guest

    Hi!

    I have the following situation

    public class Class1 : WebControl
    {
    public Class1()
    : base(HtmlTextWriterTag.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">500x<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
    , Sep 25, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Guest
    Replies:
    2
    Views:
    723
  2. Nirosh
    Replies:
    0
    Views:
    627
    Nirosh
    Apr 28, 2009
  3. Rick
    Replies:
    3
    Views:
    8,089
    Alexey Smirnov
    Apr 13, 2010
  4. Kasabaarde Sumta

    WebControl inside of WebControl and attaching events

    Kasabaarde Sumta, Dec 13, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    174
    Kasabaarde Sumta
    Dec 13, 2004
  5. Raymond Tellenbach via .NET 247

    Persist properties to aspx file on webcontrol creation

    Raymond Tellenbach via .NET 247, Aug 4, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    116
    Raymond Tellenbach via .NET 247
    Aug 4, 2004
Loading...

Share This Page