Dropdownlist in Server Control loses Viewstate

Discussion in 'ASP .Net Building Controls' started by Graham Stevenson, Dec 1, 2003.

  1. Hi,

    I am trying to create a webpart with a dropdownlist (MS
    say it is the same as an asp.net server control).

    All works fine except that the ddlist does NOT maintain
    its viewstate (I have set EnableViewState = true).

    Controls are all being created in CreateChildControls
    override (as recommended), and other controls (Textboxes,
    checkbox) retrieve their viewstate correctly at the end
    of CreateChildControls during the postback, but the
    ddlist is always empty, and I can never get a slecteditem.

    Looking at the generated page - the __Viewstate entry is
    the same if ddlist enableviewstate is true or false -
    hence its not getting sent to the browser.

    What simple trick am I missing here ??.

    Many Thanks
     
    Graham Stevenson, Dec 1, 2003
    #1
    1. Advertising

  2. Graham Stevenson

    Teemu Keiski Guest

    Hi,

    can you post some code?

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist

    "Graham Stevenson" <> wrote in message
    news:104701c3b810$bb13f260$...
    > Hi,
    >
    > I am trying to create a webpart with a dropdownlist (MS
    > say it is the same as an asp.net server control).
    >
    > All works fine except that the ddlist does NOT maintain
    > its viewstate (I have set EnableViewState = true).
    >
    > Controls are all being created in CreateChildControls
    > override (as recommended), and other controls (Textboxes,
    > checkbox) retrieve their viewstate correctly at the end
    > of CreateChildControls during the postback, but the
    > ddlist is always empty, and I can never get a slecteditem.
    >
    > Looking at the generated page - the __Viewstate entry is
    > the same if ddlist enableviewstate is true or false -
    > hence its not getting sent to the browser.
    >
    > What simple trick am I missing here ??.
    >
    > Many Thanks
    >
    >
     
    Teemu Keiski, Dec 2, 2003
    #2
    1. Advertising

  3. Graham Stevenson

    Guest Guest

    Hi,

    Well I could do but I gave up on it, thinking that it
    would be best not to use viewstate for a large list
    anyway (as it would slow the page).

    So - instead I now use (and have working ;-)) a local
    client mechanism :

    1. Create a simple hidden input control on the page (with
    fixed name !!). NB I tried to use the control automatic
    name - but it always gives a browser error. The control
    name is 'Header:xxxxx:_ctl2', and the browser seems to
    ignore the ':' if I type this into the onchange event -
    says it can't find control named '_ctl2'. So I gave up on
    that also !!! - well I've wasted DAYS on this problem !!.

    2. In the ddlist 'onchange' event, set the current
    selection into my hidden control.

    3. When posted back - find my control in the Request.Form

    4. Use the data in here as the users selection :).

    It works, its pretty fast, and its not unreasonable...

    The code still doesn't generate a 'SelectedIndexChanged'
    event, but it does do a Postback when ddlist set to Auto.

    Thanks for coming back though....

    Regards

    Graham

    >-----Original Message-----
    >Hi,
    >
    >can you post some code?
    >
    >--
    >Teemu Keiski
    >MCP, Microsoft MVP (ASP.NET), AspInsiders member
    >ASP.NET Forum Moderator, AspAlliance Columnist
    >
    >"Graham Stevenson" <>

    wrote in message
    >news:104701c3b810$bb13f260$...
    >> Hi,
    >>
    >> I am trying to create a webpart with a dropdownlist (MS
    >> say it is the same as an asp.net server control).
    >>
    >> All works fine except that the ddlist does NOT maintain
    >> its viewstate (I have set EnableViewState = true).
    >>
    >> Controls are all being created in CreateChildControls
    >> override (as recommended), and other controls

    (Textboxes,
    >> checkbox) retrieve their viewstate correctly at the end
    >> of CreateChildControls during the postback, but the
    >> ddlist is always empty, and I can never get a

    slecteditem.
    >>
    >> Looking at the generated page - the __Viewstate entry

    is
    >> the same if ddlist enableviewstate is true or false -
    >> hence its not getting sent to the browser.
    >>
    >> What simple trick am I missing here ??.
    >>
    >> Many Thanks
    >>
    >>

    >
    >
    >.
    >
     
    Guest, Dec 3, 2003
    #3
    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. Spam Catcher
    Replies:
    0
    Views:
    600
    Spam Catcher
    Feb 18, 2006
  2. Replies:
    0
    Views:
    1,851
  3. Fahim
    Replies:
    0
    Views:
    487
    Fahim
    Aug 18, 2006
  4. Dwight Johnson
    Replies:
    0
    Views:
    2,784
    Dwight Johnson
    Oct 7, 2008
  5. Robert Phillips

    Disabled Panel control loses viewstate

    Robert Phillips, Apr 28, 2004, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    298
    Scott Mitchell [MVP]
    Apr 28, 2004
Loading...

Share This Page