Aspx and hidden WebControl properties

R

rrutkowski

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top