how does viewstate appear?

  • Thread starter Thread starter suzy
  • Start date Start date
S

suzy

i am having problems after problems...

first i tried to create a page template and finally got that to work. so
currently all my pages inherit from a template page class.

i am adding controls to my page dynamically (so my html designer has no html
code in it). the problem is if i view the source of my page in my browser
there is no viewstate control.

how do i get this to appear? dont i need this to use server controls?
 
you need a <form runat="server"></form> in there in order for viewstate to
work.

Karl
 
Unless you're adding controls to a WebForm (<form runat=server...>), you
won't HAVE any ViewState, and your Server Controls won't work properly.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
http://www.takempis.com
Complex things are made up of
lots of simple things.
 
hi,

i have that in my code but it isn't working. do you think it's because i am
using a page template and inheriting from another page template class?

i have added the following line to my template class
....

Controls.Add (new LiteralControl ("<form id='frmbody' name='frmBody'
method='post' runat='server'>"));

Controls.Add (Body); // this is a placeholder

Controls.Add (new LiteralControl ("</form>"));

....
 
don't think that would work...instead of adding a literalcontrol that has an
html form...try adding an HtmlControls.HtmlForm...

HtmlForm Form = new HtmlForm();
HtmlForm.Controls.Add(Body)
Controls.Add(HtmlForm)

make sure to add ur body to your form....and then the form to the containing
control.

this quasy-quality article might help:
http://www.devarticles.com/art/1/304/2

Karl
 
Back
Top