Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > dynamic control and viewState

Reply
Thread Tools

dynamic control and viewState

 
 
Frank
Guest
Posts: n/a
 
      09-10-2003
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




 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Failed to load viewstate. The control tree into which viewstate... Josema ASP .Net Building Controls 2 05-22-2005 10:38 AM
Failed to load viewstate. The control tree into which viewstate... Josema ASP .Net Web Controls 0 05-09-2005 10:58 AM
Viewstate and dynamic control Mick ASP .Net 1 01-07-2005 12:22 PM
Dynamic Control Creation and ViewState: what is the ASP.Net way? PABruceFan ASP .Net Web Controls 3 07-31-2004 06:43 PM
Dynamic Control Creation and ViewState: what is the ASP.Net way? PABruceFan ASP .Net 3 07-31-2004 06:43 PM



Advertisments