why is the selectedvalue of this dropdownlist empty?

Discussion in 'ASP .Net' started by Bart, May 29, 2007.

  1. Bart

    Bart Guest

    Hi,

    This code sends back the selectedvalue of a dropdownlist to itself
    (postabck).
    But the value (dd in the code) is empty.
    I must say: it works with EnableViewState="true".

    My question is: dropdownlist control doesn't need viewstate for keeping the
    value when the ListItems are put declaratively. Why not when the ListItems
    are put programmatically?

    Thanks
    Bart
     
    Bart, May 29, 2007
    #1
    1. Advertising

  2. Bart

    bruce barker Guest

    if a select is declared declaratively, on postback the item values are
    set in oninit by the code the form generates.

    if you dynamically update the list, you need to also do it in oninit of
    the postback.

    if viewstate is enabled, the list is stored in viewstate, and the
    control reloades the list in onviewstate load. also the render value is
    saved, so the onchange event can be fired.

    -- bruce (sqlwork.com)

    Bart wrote:
    > Hi,
    >
    > This code sends back the selectedvalue of a dropdownlist to itself
    > (postabck).
    > But the value (dd in the code) is empty.
    > I must say: it works with EnableViewState="true".
    >
    > My question is: dropdownlist control doesn't need viewstate for keeping the
    > value when the ListItems are put declaratively. Why not when the ListItems
    > are put programmatically?
    >
    > Thanks
    > Bart
    >
    >
     
    bruce barker, May 29, 2007
    #2
    1. Advertising

  3. Bart

    David Wier Guest

    If you put them in programmatically, in the page load, it reloads every time
    the page posts back
    You must surround the loading of the ddl with an postback block (if not
    page.ispostback then...)

    --
    David Wier
    MVP/ASPInsider
    http://aspnet101.com
    http://iWritePro.com



    "Bart" <b@s> wrote in message
    news:%...
    > Hi,
    >
    > This code sends back the selectedvalue of a dropdownlist to itself
    > (postabck).
    > But the value (dd in the code) is empty.
    > I must say: it works with EnableViewState="true".
    >
    > My question is: dropdownlist control doesn't need viewstate for keeping
    > the value when the ListItems are put declaratively. Why not when the
    > ListItems are put programmatically?
    >
    > Thanks
    > Bart
    >
     
    David Wier, May 29, 2007
    #3
  4. Bart

    Bart Guest

    Thanks to both

    "David Wier" <> schreef in bericht
    news:...
    > If you put them in programmatically, in the page load, it reloads every
    > time the page posts back
    > You must surround the loading of the ddl with an postback block (if not
    > page.ispostback then...)
    >
    > --
    > David Wier
    > MVP/ASPInsider
    > http://aspnet101.com
    > http://iWritePro.com
    >
    >
    >
    > "Bart" <b@s> wrote in message
    > news:%...
    >> Hi,
    >>
    >> This code sends back the selectedvalue of a dropdownlist to itself
    >> (postabck).
    >> But the value (dd in the code) is empty.
    >> I must say: it works with EnableViewState="true".
    >>
    >> My question is: dropdownlist control doesn't need viewstate for keeping
    >> the value when the ListItems are put declaratively. Why not when the
    >> ListItems are put programmatically?
    >>
    >> Thanks
    >> Bart
    >>

    >
    >
     
    Bart, May 30, 2007
    #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. Jesse
    Replies:
    3
    Views:
    1,268
    DudeGuy
    Jul 24, 2003
  2. Tom Jorgenson
    Replies:
    3
    Views:
    7,066
  3. gu4y
    Replies:
    4
    Views:
    6,882
    mngates
    Jan 13, 2010
  4. Sudhir

    Dropdownlist.SelectedValue ISSUE

    Sudhir, Feb 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    484
    Scott Mitchell [MVP]
    Feb 26, 2004
  5. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,261
    Smokey Grindel
    Dec 2, 2006
Loading...

Share This Page