WebControl State: ViewState or Request.Form?

  • Thread starter Thread starter Patrice
  • Start date Start date
Basically it is dependant on what you intend the control to do and how to
work.As was said, there is no preset rule, it all depends on the
functionality of the control and what it does over the postbacks. Also what
it uses as underlying HTML elements is crucial (some of them are posted,
some aren't).
 
Hi,

I'm still a little bit confused with how managing a webcontrol state over
postbacks...
Should I use the form's post values to populate the control on the server
side when possible, or should I always use the viewstate mechanism?

For instance, I noticed that the TextBox webcontrol does not depend on the
viewstate.
I guess it uses the form to retrieve state (the input is submited of course)
over roundtrips...

Also, the control should manage its state independenty.
No matter if it is used directly by the page, or by a parent composite
control it should save state by its own (like the TextBox webcontrol).

Thanks,
Hadar
 
Hadar,

There is no general answer to your question. There is a number of factors to
consider. Imagine you have a dropdown list that you populate with just a few
lines but in order to obtain the lines you have to run a heavy database
query. Then, obviously, you would prefer running the query once and saving
the lines in the viewstate. In other case, when you have a dropdown list for
selecting time of day with 15 minutes increment, you would prefer populating
the list with a few lines of code on every round trip.

Eliyahu
 
Back
Top