N
news.microsoft.com
Hi,
I'm building a custom control and I have an issue. My custom control has a
(Server) TextBox control in it and my custom contol exposes a property named
Text. I want my Text property displayed within my TextBox (So I basically
set TextBox.Text property = Text (that is custom control's Text property) in
my CreateChildControls method. But in design mode when I set my (custom
control's) Text property the change is not reflected to Text property of my
TextBox. What is the most efficient way to achieve this? (I guess calling
EnsureChildControls in custom control's Text property set accessor is not a
very good idea and sometimes it works sometimes not.) Also I am not
overriding Render method. Psuedo-like code follows:
// Some Attributes...
public class MyControl: WebControl, INamingContainer
....
public string Text
{
get
{
return ( ViewState["Text"] == null ? String.Empty :
ViewState["Text"] )
}
set
{
ViewState["Text"] = value;
}
}
protected override void CreateChildControls()
{
base.CreateChildControls();
TextBox textBox = new TextBox();
textBox.ID = "myTextBox";
textBox.Text = this.Text;
this.Controls.Add(textBox);
this.ChildControlsCreated = true;
}
When I change Text property in design-mode textBox.Text does not change
until page is refreshed (in design-mode).
I will appreciate suggestions or best practices to achieve this. Thanks in
advance.
I'm building a custom control and I have an issue. My custom control has a
(Server) TextBox control in it and my custom contol exposes a property named
Text. I want my Text property displayed within my TextBox (So I basically
set TextBox.Text property = Text (that is custom control's Text property) in
my CreateChildControls method. But in design mode when I set my (custom
control's) Text property the change is not reflected to Text property of my
TextBox. What is the most efficient way to achieve this? (I guess calling
EnsureChildControls in custom control's Text property set accessor is not a
very good idea and sometimes it works sometimes not.) Also I am not
overriding Render method. Psuedo-like code follows:
// Some Attributes...
public class MyControl: WebControl, INamingContainer
....
public string Text
{
get
{
return ( ViewState["Text"] == null ? String.Empty :
ViewState["Text"] )
}
set
{
ViewState["Text"] = value;
}
}
protected override void CreateChildControls()
{
base.CreateChildControls();
TextBox textBox = new TextBox();
textBox.ID = "myTextBox";
textBox.Text = this.Text;
this.Controls.Add(textBox);
this.ChildControlsCreated = true;
}
When I change Text property in design-mode textBox.Text does not change
until page is refreshed (in design-mode).
I will appreciate suggestions or best practices to achieve this. Thanks in
advance.