J
J.Marsch
I'm a little new to Web Forms, and building web form controls:
I am trying to build a simple composite web form control. It contains a
Label, with a TextBox
At design time, if the user attempts to resize the control, I want for the
Textbox to resize along with it, so that its width matches that of the
container, and if you change the height of the container, the height of the
Textbox is adjusted -- basically, the text box should take up the entire
container except for the space used by the Label.
No matter how hard I fight it, I cannot seem to get this resize behavior to
work right.
What seems to be throwing me off is that it appears to be possible to have
an empty height. How can I figure out how to set the height of the
contained control if the label shows a height of 0? It's height obviously
isn't zero, because I can see it when it renders. I think that there is
either a bug, or something basic that I don't follow.
I didn't think it should be too difficult. Here's basically what I've got:
(leaving out some additional complexity)
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
this.EnsureChildControls();
this.EditControl.Width = this.Width;
this.EditControl.Height = new Unit(this.Height.Value -
this.FieldLabel.Height.Value);
base.Render(writer);
}
protected override void CreateChildControls()
{
this.FieldLabel = new Label();
this.Controls.Add(this.FieldLabel);
this.EditControl = new TextBox();
this.Controls.Add(this.EditControl);
I am trying to build a simple composite web form control. It contains a
Label, with a TextBox
At design time, if the user attempts to resize the control, I want for the
Textbox to resize along with it, so that its width matches that of the
container, and if you change the height of the container, the height of the
Textbox is adjusted -- basically, the text box should take up the entire
container except for the space used by the Label.
No matter how hard I fight it, I cannot seem to get this resize behavior to
work right.
What seems to be throwing me off is that it appears to be possible to have
an empty height. How can I figure out how to set the height of the
contained control if the label shows a height of 0? It's height obviously
isn't zero, because I can see it when it renders. I think that there is
either a bug, or something basic that I don't follow.
I didn't think it should be too difficult. Here's basically what I've got:
(leaving out some additional complexity)
protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
this.EnsureChildControls();
this.EditControl.Width = this.Width;
this.EditControl.Height = new Unit(this.Height.Value -
this.FieldLabel.Height.Value);
base.Render(writer);
}
protected override void CreateChildControls()
{
this.FieldLabel = new Label();
this.Controls.Add(this.FieldLabel);
this.EditControl = new TextBox();
this.Controls.Add(this.EditControl);