I am using js function to add items in dropdownlist.All items are added perfectly but when I want to add selected value from that in DB,On clicking button the dropdownlist gets reset on postback.
How can I stop this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The items are lost on postback because they are added client side through javascript, and do not exist in viewstate.
An option would be to add an
<asp:hiddenfield />, and add some javascript code to theonChangeevent of your dropdown to write the selectedvalue into the hiddenfield input. This value will then be accesible after postback. You still have to re-populate the dropdown again after postback though.Example: