F
Frank
Hi all,
I want to create a control dynamically and keep viewState.
I got the following code from a google search which works.
private void Page_Load(object sender, System.EventArgs e) {
TextBox tb = new TextBox();
tb.ID = "vic";
FindControl("Form1").Controls.Add( tb );
if(!IsPostBack)
tb.Style.Add("background-color","red");
}
but if I move FindControl("Form1").Controls.Add( tb ); to the end like this:
TextBox tb = new TextBox();
tb.ID = "vic";
if(!IsPostBack)
tb.Style.Add("background-color","red");
FindControl("Form1").Controls.Add( tb );
It does not work anymore. ViewState is not written to client. Does it mean
that the viewState is
added by .NET at the line of tb.Style.Add("background-color","red") ?
Thanks.
Frank
I want to create a control dynamically and keep viewState.
I got the following code from a google search which works.
private void Page_Load(object sender, System.EventArgs e) {
TextBox tb = new TextBox();
tb.ID = "vic";
FindControl("Form1").Controls.Add( tb );
if(!IsPostBack)
tb.Style.Add("background-color","red");
}
but if I move FindControl("Form1").Controls.Add( tb ); to the end like this:
TextBox tb = new TextBox();
tb.ID = "vic";
if(!IsPostBack)
tb.Style.Add("background-color","red");
FindControl("Form1").Controls.Add( tb );
It does not work anymore. ViewState is not written to client. Does it mean
that the viewState is
added by .NET at the line of tb.Style.Add("background-color","red") ?
Thanks.
Frank