Joe

Joe

  • NA
  • 1
  • 1.7k

Custom Server Control

Aug 5 2010 11:47 AM
I'm trying to write a Server Control that has some of its properties updated based on the values of other properties. For example, I have a Control that implements the WebControls.TextBox. When the "Text" is changed during "Design-Time", the "Width" of the Control is adjusted based on the length of the Text. This all works but the problem is the "Width" value is NOT written to the control declared in the HTML. If I change the "Width" in the PropertyGrid, the "Width" value is written to the HTML. How can I force the Width to be written to the HTML page when it is changed in code?

HTML Code of the Control - I need the "Width" property to be written here when the value is changed in code
Code:
<cc1:ServerControl1 ID="ServerControl1" runat="server">My text </cc1:ServerControl1>
Sample Control
Code:
public class ServerControl1 : TextBox
{
public override string Text
{
get { return base.Text; }
set
{
base.Text = value;
//Dynamically change the Textbox Control's Width based on the length of the Text
this.Width = value.Length * 20;
}
}
}
This is needed for design-time purposes.

Thanks,
Joe