javascript populates dropdownlist

G

Guest

I have what may be a ViewState problem, but don't know how to deal with it:

I have 2 DropDownLists: ddlMed and ddlDosage. When the user selects a
medication from ddlMed, a javascript fires to populate ddlDosage with the
proper dosages for that medication. This works fine and the user is then
able to select a dosage and save the page.

The problem is that when the user hits the Save button, c# code processes
the form and saves the record and finds that the ddlDosage.SelectedValue is
empty, eventhough the user was able to see and select items from the
DropDownList.

I suspect the problem is related to the fact that the ddlDosage DropDownList
was populated on the client side and the server can't see it. Is that
correct? How can I make this work?
Thanks
/Ken
 
G

Guest

I have what may be a ViewState problem, but don't know how to deal with it:

I have 2 DropDownLists: ddlMed and ddlDosage. When the user selects a
medication from ddlMed, a javascript fires to populate ddlDosage with the
proper dosages for that medication. This works fine and the user is then
able to select a dosage and save the page.

The problem is that when the user hits the Save button, c# code processes
the form and saves the record and finds that the ddlDosage.SelectedValue is
empty, eventhough the user was able to see and select items from the
DropDownList.

I suspect the problem is related to the fact that the ddlDosage DropDownList
was populated on the client side and the server can't see it. Is that
correct? How can I make this work?
Thanks
/Ken

you can make a hidden field that capture your value for second list
and use it in your code

For example, make this in your form

<input id="__Dosage" type="hidden" name="__Dosage" runat="server">

When javascript populated ddlDosage, make the following

document.getElementById("__Dosage").value=...;

and make

Me.ddlDosage.Attributes.Add("onchange",
"document.getElementById('__Dosage').value=this.value;")

Finally your selected value in code-behind will be as

Me.__Dosage.Value
 
K

Ken Smith

Alexey,
Thank you for the assistance -- with examples no less. It worked perfectly.
Spasiba
 

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

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top