Viewstate Question

Discussion in 'ASP .Net' started by Patrick.O.Ige, Aug 23, 2005.

  1. 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?
     
    Patrick.O.Ige, Aug 23, 2005
    #1
    1. Advertising

  2. Yes, give them different names:

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

    Eliyahu

    "Patrick.O.Ige" <> wrote in message
    news:...
    > 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?
    >
    >
     
    Eliyahu Goldin, Aug 23, 2005
    #2
    1. Advertising

  3. 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.




    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, Aug 23, 2005
    #3
  4. 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" ने लिखा:

    > 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.
    >
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    >
     
    =?Utf-8?B?U2FjaGluIFNha2k=?=, Aug 23, 2005
    #4
  5. 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


    *** Sent via Developersdex http://www.developersdex.com ***
     
    Patrick Olurotimi Ige, Aug 24, 2005
    #5
  6. 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


    --
    Cr Cr


    "Patrick Olurotimi Ige" wrote:

    > 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
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    >
     
    =?Utf-8?B?Q29tcHV0ZXIgUm9nZXI=?=, Sep 10, 2005
    #6
  7. Patrick.O.Ige

    john_teague Guest

    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
     
    john_teague, Sep 12, 2005
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Rush
    Replies:
    2
    Views:
    574
    Ben Rush
    Dec 5, 2003
  2. Steph
    Replies:
    2
    Views:
    1,696
    heislord5
    May 11, 2011
  3. ujjc001
    Replies:
    0
    Views:
    1,399
    ujjc001
    Jul 27, 2005
  4. sck10
    Replies:
    6
    Views:
    957
    sck10
    Sep 1, 2006
  5. mark

    Viewstate errors... how do I get viewstate working?

    mark, Feb 20, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    299
Loading...

Share This Page