all groups > asp.net webcontrols > october 2005 >
You're in the

asp.net webcontrols

group:

Value and text are nothing on postback if ddl is filled client sid



Value and text are nothing on postback if ddl is filled client sid Chris Lane
10/31/2005 7:59:11 AM
asp.net webcontrols: Hi,

Can somebody please explain why after postback a dropdownlist
selectedindex.value and text are nothing if the dropdownlist was populated
clientside with javascript.
Are there any workarounds besides using the request object to get the value
of the dropdownlist?

Thanks,

Re: Value and text are nothing on postback if ddl is filled client sid Oleg Kap
10/31/2005 8:45:56 AM
Hello Chris,
If you populate you drop down list on the client side, server side has no
knowledge of it.
It doesnt submit all values in the drop down list.
I cant think of any other way know to get those values other then using Request
object.
If you going to use this in many pages you might consider to write your own
component where client side will populate data and your component will submit
all values to the server side.

Hope it helps,
Oleg

[quoted text, click to view]

RE: Value and text are nothing on postback if ddl is filled client sid Phillip Williams
10/31/2005 9:15:17 AM
Hi Chris,

Server controls that are composed on the server-side write a ViewState
encrypted on the rendered HTML page (if you right-mouse click on the page and
view the source of your HTML you will see an <input type="hidden"
name="__VIEWSTATE" > whose value contains the encrypted ViewState.

When you add an <option> to a dropdown list using JavaScript, you are not
adding equivalent values into the ViewState and therefore upon PostBack there
is no way for the ASP page to realize your changes.

A work around is to create <input type="hidden"> tags to manage your own
addition to the HTML, e.g.
<input type="hidden" id="AddedToMyDropDownList" value="Item1Val|Item1Text|
item2Val|Item2Text"> then on the server side while handling the Page.Load you
would process this value and add the new items to your dropdown list before
the method that would handle the SelectedIndexChanged event.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


[quoted text, click to view]
RE: Value and text are nothing on postback if ddl is filled client sid Chris Lane
10/31/2005 10:11:13 AM
AddThis Social Bookmark Button