Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Dropdownlist in Server Control loses Viewstate

Reply
Thread Tools

Dropdownlist in Server Control loses Viewstate

 
 
Graham Stevenson
Guest
Posts: n/a
 
      12-01-2003
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


 
Reply With Quote
 
 
 
 
Teemu Keiski
Guest
Posts: n/a
 
      12-02-2003
Hi,

can you post some code?

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

"Graham Stevenson" <(E-Mail Removed)> wrote in message
news:104701c3b810$bb13f260$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Guest
Posts: n/a
 
      12-03-2003
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 'Headerxxxx:_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" <(E-Mail Removed)>

wrote in message
>news:104701c3b810$bb13f260$(E-Mail Removed)...
>> 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
>>
>>

>
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
UpdatePanel control loses ViewState data if Visible property setOptions Dwight Johnson ASP .Net 0 10-07-2008 06:24 PM
Control loses viewstate inside HeaderTemplate of DataList Fahim ASP .Net 0 08-18-2006 12:17 PM
Serialized class in web user control loses viewstate on postback bminder@gmail.com ASP .Net 0 04-07-2006 01:09 AM
HELP: Inherited User Control Loses ViewState Spam Catcher ASP .Net 0 02-18-2006 06:41 AM
Disabled Panel control loses viewstate Robert Phillips ASP .Net Web Controls 3 04-28-2004 06:52 PM



Advertisments