[RESOLVED]asp.net throws an error when dropdown in filled using jquery

Dear All,

i have one asp.net page(vb.net). i have two dropdownlist state and district. i filled district from state using Jquery.

Now the problem is when i submit page it throws an exception..

how can i solve this?

Hi,

priya15_patel

i have two dropdownlist state and district. i filled district from state using Jquery.

Use dropdownlist (servercontrol) only for state

and use <select> (htmlcontrol) for district  and save its value during onchange event in a HiddenField (servercontrol).

You are facing Error because, asp.net not allows html injected from clientside(browser).

thank you so much for your valuable reply. but i want to do reverse process too. like if i fetch data from database then

i need to set dropdown value. how will it be possible from code behind to set html control value.?

another reason web forms is painful when using javascript. in web forms the complete list of legal downtown values is stored in view state. on postback this list is used to rebuild the dropdown list, so that it can be set to the postback value.

your fix, is in PreInit you need to add the postback value to drop down list, so that it can be set during the apply postback data event. this is the same approach you use if you turn viewstate off (a really good practice).  

your other option is write you own custom control that implements <select> that does not have this limitation.

 

Leave a Reply