WebControl State: ViewState or Request.Form?

T

Teemu Keiski

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).
 
H

Hadar

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
 
E

Eliyahu Goldin

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,140
Latest member
SweetcalmCBDreview
Top