0

I have a modal that pops up when you click a button, inside that modal I have a save button. When that save button is pressed I would like to fire some C# code in a with an OnClick function....

Can anyone tell me why this isn't working for me?

ASP.NET

<div class="modal fade" id="deviceModal" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h4>Select</h4>                       
                </div>
                <div class="modal-body"> 
                    <asp:DropDownList ID="drpDownID" runat="server" CssClass="fields" EnableViewState="true">
                        <asp:ListItem Text="<Select>" Value="0" />                           
                    </asp:DropDownList>
                </div>
                <div class="modal-footer">
                    <asp:Button ID="btnSave" runat="server" Text="Save" data-dismiss="modal" CssClass="btn btn-primary" OnClick="btnSave_Click" />
                    <asp:Button ID="btnClose" runat="server" Text="Close" data-dismiss="modal" CssClass="btn btn-danger" OnClick="btnClose_Click" />
                </div>

            </div>
        </div>
    </div>

C#

protected void btnSave_Click(object sender, EventArgs e)
    {
        string test = "";
        test = drpDownID.SelectedItem.ToString();
    }

It won't even hit my break point.... And this is embedded in a form tag with a runat server

It works fine if I take the save button outside of the modal, but that completely defeats the purpose of the modal. So it has to be something with modal don't like click events very much...

B.K.
  • 9,982
  • 10
  • 73
  • 105
John Doe
  • 3
  • 1
  • 2

2 Answers2

0

Have you tried adding () to the onclick? like OnClick="btnSave_Click()".

EDIT: You can probably ignore that. It doesn't seem to matter for asp tags. Maybe this question can help you: ASP.NET button inside bootstrap modal not triggering click event

Community
  • 1
  • 1
levelonehuman
  • 1,465
  • 14
  • 23
0

If your click on the save doesn't trigger a postback inside the dialog and it does outside the dialog: Can you use Firebug in Firefox to see whether the Save button is still part of the form?

I know JQuery dialog brings the container to the bottom of the body and therefor takes it out of a possible form, resulting in form posts not triggering from dialogues. I have a nice fix for this JQuery dialog issue, but that's probably not part of this topic.

Dacker
  • 892
  • 2
  • 8
  • 12