3

I am trying to get the selected value from dropdownlist which is open in jquery dialog. This is the code I have.

<div id="add_new_user" class="dialog-content table-options-modal large-label-form" title="User Access">
    <div class="form-inline form-wrapper">
        <div class="modal-body">
            <div class="col-sm-6">
                <div class="large-label form-group">
                    <asp:DropDownList runat="server" ID="drpUserType">
                        <asp:listitem text="--Select--" value="0" />
                        <asp:listitem text="aaa" value="1" />
                        <asp:listitem text="bbb" value="2" />
                    </asp:DropDownList>
                </div>
            </div>
        </div>
        <div class="modal-footer">
            <asp:Button ID="btnSave" class="btn btn-gray btn-fixed" runat="server" OnClick="btnSave_Click" Text="Save"></asp:Button>
        </div>
    </div>
</div>

Code behind :

protected void btnSave_Click(object sender, EventArgs e)
{
    int drpValue = drpUserType.SelectedValue.ToInt();
}

The problem is, every time I got '0' value. Thank you.

Prashant16
  • 1,514
  • 3
  • 18
  • 39

1 Answers1

0

This is an older question, but I had the same issue and figured it out.

JQueryUI dialogs are moved outside the form. You can verify in your browser's console by typing...

$("form").find("#drpUserType")

...once the dialog is displayed.

With the DropDownList control now outside the form, it won't be present on the postback. You can reappend the DropDownList to the form with some extra code in your dialog's close event.

Do something like this:

$("#drpUserType").appendTo("form")

See also: jQuery modal form dialog postback problems

trw
  • 239
  • 1
  • 11