Viewstate Question

P

Patrick.O.Ige

I'm constructing a link from a viewstate and passing it on to a
querystring..
After clciking a checkboxlist i add the value to a viewstate and return it
but on the same page i also have a dropdwonlist whcih also does similar.
But i noticed that after selecting a checkBox and it appends the value tot
he Querystring and then i select a dropdownlist..
The Viewstate onluy returns the dropdownlist value and the checkboxlist is
gone..
Is there a way to return both at the same time from viewstate?
 
E

Eliyahu Goldin

Yes, give them different names:

ViewState("cblValue")
ViewState("ddlValue")

Eliyahu
 
P

Patrick Olurotimi Ige

Eliyahu,
Thanks for the reply and i have given them different values and
added them to the ViewState before.
But the problem is when a checkbox is selected i get the selected value
but after selecting the checkbox values goes off but the DropDownLis
selected value retains.
What 'm doing is adding them to the Viewstate and later remove them in
the Page_load when the user uncheck the checkbox.
What i want to do is to keep the selected values of the CheckBoxes and
DropDownlist when selected and append them to my QueryString but only
the recent selected values show at the moment.
 
G

Guest

Hi,

I think what you are trying to do is right, but may your dropdown makes a
postback I mean check the property "AutoPostBack" of dropdown, if it is true
then first page_Load will be fired and as you are removing data from
viewstate on Page_Load. That the reason it is happening.

To slove make the AutoPostBack set to False as it is bydefault false.

Regards,
Sachin Saki
..NET Developer - Capgemini, INDIA

"Patrick Olurotimi Ige" ने लिखा:
 
P

Patrick Olurotimi Ige

Sachin thanks for the reply but i need the Autpostback to get the
selected values..
My problem here is that when the DropDownList is selected and since i
have "ViewState.Remove("myddl")" in the page_load .
I need to remove the Viewstate since if the user unchecks the
CheckBoxlist or Unselect the Dropdownlist i need to remove the value
from the Viewstate..
Any solutions..
Patrick
 
G

Guest

Hi Patrick,

Use the following simple rule:

When saving variables across post-backs, save those variables in the
SessionState. Use ViewState only to detect changes to controls and then
update your SessionState from those events.


If you have one class that maintains your SessionState, you only have to
retrieve that single object when you receive your post-back. The
SessionState object can be a well-known name that all ascx controls and your
aspx page can access.

You might also create another single well-known object that provides access
to all variables that are not to be saved across post-backs but whose members
would be refreshed from your database on an as needed basis. (per request
such as account balances, other real-time stuff).

These might be named something like: SessionDoc and RequestDoc respectively.

I hope that helps.

Roger
 
J

john_teague

The selected Items should already be stored in viewstate via the
cblControl / ddlControl.SelectedValue

If you need to remove the selected item set SelectedIndex to -1
 

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

Similar Threads

viewstate 2
Querystring or ViewState question 1
viewstate 0
Problem with control and ViewState 3
ViewState 0
Invalid Viewstate remote 1
ViewState or QueryString 1
Viewstate and mobile clients 0

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top