Problem with Dropdown - ViewState and AutoPostBack

Discussion in 'ASP .Net' started by Lloyd Sheen, Nov 8, 2003.

  1. Lloyd Sheen

    Lloyd Sheen Guest

    I have a page that works fine. I am trying to optimize the page by
    overriding some of the Information that is being saved in the hidden
    VIEWSTATE.

    If I make the properties of the dropdown False for ViewState and True for
    AutoPostBack, it does reload the page but does not call the
    SelectedIndexChanged event. If I put the ViewState to True then it is
    called.

    Does this mean that I cannot get that event and deal with it in better code
    than what is required by using both the ViewState and AutoPostBack to true.
    I want to cache some info so that is retrieved only when necessary not on
    every page load.
    Lloyd Sheen, Nov 8, 2003
    #1
    1. Advertising

  2. Lloyd Sheen

    Lloyd Sheen Guest

    More info. A small project with a button and a listbox (ViewState =
    "False") causes the following. If I click the listbox to change the
    selection nothing happens. If I then click the button first the
    ListBoxSelection Change happens then the Button Click.

    Does this mean that the only way to get the listbox to send events (when
    they happen) is to have the view state enabled??

    If so I can only see this as a problem if you are trying to optimize the
    code for page loads.


    "Lloyd Sheen" <> wrote in message
    news:ha9rb.180841$...
    > I have a page that works fine. I am trying to optimize the page by
    > overriding some of the Information that is being saved in the hidden
    > VIEWSTATE.
    >
    > If I make the properties of the dropdown False for ViewState and True for
    > AutoPostBack, it does reload the page but does not call the
    > SelectedIndexChanged event. If I put the ViewState to True then it is
    > called.
    >
    > Does this mean that I cannot get that event and deal with it in better

    code
    > than what is required by using both the ViewState and AutoPostBack to

    true.
    > I want to cache some info so that is retrieved only when necessary not on
    > every page load.
    >
    >
    >
    Lloyd Sheen, Nov 8, 2003
    #2
    1. Advertising

  3. Lloyd Sheen

    -=Chris=- Guest

    By default, the autopostback property of non-button type controls is set to
    false. Without a post back your selection change event will not fire until
    the next post back. When a form is posted back, all pending events are
    processed. This is why the selection change happens as well as the button
    click when you click it. To make the page process the selection change box
    immediately, you need to set the autopostback property of the listbox to
    true. This is completely unrelated to the viewstate.



    I was minding my own business when Lloyd Sheen blurted out:

    > More info. A small project with a button and a listbox (ViewState =
    > "False") causes the following. If I click the listbox to change the
    > selection nothing happens. If I then click the button first the
    > ListBoxSelection Change happens then the Button Click.
    >
    > Does this mean that the only way to get the listbox to send events (when
    > they happen) is to have the view state enabled??
    >
    > If so I can only see this as a problem if you are trying to optimize the
    > code for page loads.
    >
    >
    > "Lloyd Sheen" <> wrote in

    message
    > news:ha9rb.180841$...
    >> I have a page that works fine. I am trying to optimize the page by
    >> overriding some of the Information that is being saved in the hidden
    >> VIEWSTATE.
    >>
    >> If I make the properties of the dropdown False for ViewState and True for
    >> AutoPostBack, it does reload the page but does not call the
    >> SelectedIndexChanged event. If I put the ViewState to True then it is
    >> called.
    >>
    >> Does this mean that I cannot get that event and deal with it in better

    code
    >> than what is required by using both the ViewState and AutoPostBack to

    true.
    >> I want to cache some info so that is retrieved only when necessary not on
    >> every page load.


    --
    Insert corny line here
    -=Chris=-, Nov 9, 2003
    #3
  4. Lloyd Sheen

    JD Guest

    With the listbox, the items are saved in the viewstate. So the first time
    your page is rendered you add the items to the listbox and everything is
    fine. When a postback happens Load View State takes place, which repopulates
    the listbox with the items that the listbox originally contained. Then after
    this Load Postback Data happens which applies the user's selection to the
    list box. If a selection took place, then the event will be fired latter on
    in the page processing.

    When you don't have viewstate enabled, on Load View State nothing in the
    ListBox is repopulated, and when Load Postback Data happens the user
    selection comes in but there are no items in the Listbox to apply the user
    selection to, hence no event. If you don't want to use viewstate, you have
    to repopulate the listbox yourself before Load Postback Data happens.
    Essentailly you are taking over the view states responsibility but the data
    is coming from server side cache, database, file, etc...


    "Lloyd Sheen" <> wrote in message
    news:OGcrb.794$...
    > More info. A small project with a button and a listbox (ViewState =
    > "False") causes the following. If I click the listbox to change the
    > selection nothing happens. If I then click the button first the
    > ListBoxSelection Change happens then the Button Click.
    >
    > Does this mean that the only way to get the listbox to send events (when
    > they happen) is to have the view state enabled??
    >
    > If so I can only see this as a problem if you are trying to optimize the
    > code for page loads.
    >
    >
    > "Lloyd Sheen" <> wrote in

    message
    > news:ha9rb.180841$...
    > > I have a page that works fine. I am trying to optimize the page by
    > > overriding some of the Information that is being saved in the hidden
    > > VIEWSTATE.
    > >
    > > If I make the properties of the dropdown False for ViewState and True

    for
    > > AutoPostBack, it does reload the page but does not call the
    > > SelectedIndexChanged event. If I put the ViewState to True then it is
    > > called.
    > >
    > > Does this mean that I cannot get that event and deal with it in better

    > code
    > > than what is required by using both the ViewState and AutoPostBack to

    > true.
    > > I want to cache some info so that is retrieved only when necessary not

    on
    > > every page load.
    > >
    > >
    > >

    >
    >
    JD, Nov 9, 2003
    #4
    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. Mad Scientist Jr
    Replies:
    1
    Views:
    572
    Eliyahu Goldin
    Jun 29, 2004
  2. Emma Gumbdough
    Replies:
    0
    Views:
    398
    Emma Gumbdough
    Jun 29, 2004
  3. Corey
    Replies:
    11
    Views:
    6,178
    Cor Ligthert
    Mar 20, 2005
  4. Corey

    Asp.net DropDownList, AutoPostBack, and ViewState

    Corey, Mar 18, 2005, in forum: ASP .Net Web Services
    Replies:
    10
    Views:
    457
    Cor Ligthert
    Mar 20, 2005
  5. Corey
    Replies:
    10
    Views:
    699
    Cor Ligthert
    Mar 20, 2005
Loading...

Share This Page