Hi Matt,
Thanks for your followup. Well, I'm also doing some test on my side. And
I've made a simple demo and which use public property to wrapper a private
field and when the property is reset, if the value is changed, I'll recall
the CreateChildControl to reconstruct the composite control. And I also
override the Load/SaveViewState method to handle the maintainance of the
controltype field. I've attached my demo class and test page in this
message, you can use OE client to view this messsage and get the
attachment. (I'll also paste the control's code in the bottom of this
message)Also, I find that you haven't register a email address for your
managed account, I recommend that you register one so that we can nofify
you when there is any update in your issues.
Anyway, if you have any updates , please feel free to let me know.
Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure!
www.microsoft.com/security (This posting is provided "AS IS", with no warranties, and confers no
rights.)
=====================================================
[DefaultProperty("Text"),
ToolboxData("<{0}:SimpleCC runat=server></{0}:SimpleCC>")]
public class SimpleCC : System.Web.UI.WebControls.WebControl
{
private string text;
private int _type = 0;
public int Type
{
get
{
return _type;
}
set
{
if(value != _type)
{
_type = value;
this.ChildControlsCreated = false;
this.EnsureChildControls();
}
}
}
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
// protected override void Render(HtmlTextWriter output)
// {
// output.Write(Text);
// }
public SimpleCC()
{
}
public SimpleCC(int type)
{
if(type>= 0 && type<3)
{
this._type = type;
}
}
protected override void LoadViewState(object savedState)
{
Triplet triplet = savedState as Triplet;
_type = (int)triplet.First;
this.ChildControlsCreated = false;
this.EnsureChildControls();
base.LoadViewState (triplet.Second);
}
protected override object SaveViewState()
{
Triplet triplet = new Triplet(_type,base.SaveViewState());
return triplet;
}
protected override void CreateChildControls()
{
//base.CreateChildControls ();
Controls.Clear();
switch(_type)
{
case 0:
Label lbl = new Label();
lbl.ID = "lblDynamic";
lbl.Text = "Dynamic Label";
Controls.Add(lbl);
break;
case 1:
TextBox txt = new TextBox();
txt.ID = "txtDynamic";
txt.AutoPostBack = true;
txt.TextChanged +=new EventHandler(txt_TextChanged);
Controls.Add(txt);
break;
case 2:
Button btn = new Button();
btn.ID = "btnDynamic";
btn.Text = "Dynamic Button";
btn.Click +=new EventHandler(btn_Click);
Controls.Add(btn);
break;
}
}
protected void txt_TextChanged(object source, EventArgs argument)
{
TextBox txt = (TextBox)source;
Page.Response.Write("<br>" + txt.ID + " posted back");
}
protected void btn_Click(object source, EventArgs argument)
{
Button btn = (Button)source;
Page.Response.Write("<br>" + btn.ID + " posted back");
}
}