Results 1 to 4 of 4

Thread: clearing viewstate for individual controls

  1. #1

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    clearing viewstate for individual controls

    I have a listbox thats databound, the data behind will chnage depending on the results of other listboxes.

    The probem is I have set enabledviewstae = true and if you select a value and on the next data pull this value isnt included then i get the error
    "Specified argument was out of the range of valid values."

    I need to know how to clear the viewstate for this one control before databinding

  2. #2
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: clearing viewstate for individual controls

    Why don't you just rebind the control?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Fanatic Member davebat's Avatar
    Join Date
    Dec 2002
    Posts
    727

    Re: clearing viewstate for individual controls

    I am doing but heres an example of the problem:

    dropdown is bound and user selects an option "Yellow"

    Yellow is then stored in the viewstate for this control.

    Things happen on the page and controls gets bound to a different version of the data that doesnt include "Yellow"

    .NET then trys to set the controls selected item to "Yellow" as this is stored in viewstate and is erroring as "Yellow" no longer exists

  4. #4
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: clearing viewstate for individual controls

    So even if you did something like this:

    VB Code:
    1. '' somewhere in code
    2.     ''
    3.     drpMyDropDownList.DataSource = dtaSomeDataSet
    4.     drpMyDropDownList.Bind()

    Otherwise, is EnableViewState a read only property at runtime or could you change it to False and then back to True and perhaps that might clear it?
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width