Dropdownlist in Server Control loses Viewstate

  • Thread starter Graham Stevenson
  • Start date
G

Graham Stevenson

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
 
G

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top