Ask a Question related to ASP.NET Building Controls, Design and Development.
-
news.microsoft.com #1
Custom Control As A Composite Control
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.
news.microsoft.com Guest
-
Problems in Composite Custom Control
Hi everybody, I am trying to a build an ASP .Net Custom Control(in C#) which will create a table ( with variable number of rows) dynamically based... -
Using XSLT in a custom composite control
Yes, that says it all. I am trying to use XSLT to render the pre/post parts of the composite control in order to keep the look apart from the... -
Possible to create a composite control that has a child control that is a validator that validates the composite control itself?
I am attempting to create a composite control which has a label, followed by an optional error message, followed by two text boxes. I have... -
Validating a custom, composite web control
Hi I need to create a custom, composite server control which contains a text box that needs to be validated. I need to be able to add external... -
Using Table control in a custom composite control. Control does not render properly in design time.
All, I have written a very simple custom composite control that includes a control of type System.Web.UI.WebControls.Table. The control... -
news.microsoft.com #2
Custom Control As A Composite Control
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.
news.microsoft.com Guest
-
John Saunders #3
Re: Custom Control As A Composite Control
"news.microsoft.com" <tmp@devel.local> wrote in message
news:OEZzIEWoGHA.4040@TK2MSFTNGP05.phx.gbl...Calling EnsureChildControls in the Text property is exactly what I'd try:> 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.)
public string Text
{
get {EnsureChildControls(); return textBox.Text;}
set {EnsureChildControls(); textBox.Text = value;}
}
....
If you don't call EnsureChildControls earlier, it will be called in> protected override void CreateChildControls()
> {
> base.CreateChildControls();
> TextBox textBox = new TextBox();
> textBox.ID = "myTextBox";
> textBox.Text = this.Text;
> this.Controls.Add(textBox);
> this.ChildControlsCreated = true;
> }
PreRender, which is likely to be too late.
John
John Saunders Guest
-
sam #4
Re: Custom Control As A Composite Control
And actually doing that is standard best practice.
sam Guest



Reply With Quote

