15

I already did search online, and try a few solutions provided, but none of them are working for me.

I have a button within a div. I am displaying the div within a jquery dialog. The button click doesnt work within the jquery dialog.

I have my code below :

aspx

    <div id='one'>
 <asp:LinkButton ID="ConfigureAlerts" OnClick="btnConfigureAlerts_Click" runat="server">Configure Alerts</asp:LinkButton>
</div>
<div id="ViewModalPopupDiv2">
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">
            <ContentTemplate>
            <asp:Panel ID="Panel2" runat="server" HorizontalAlign="left" ScrollBars="Auto">
            <asp:Button ID="btnGetLogs" runat="server" Text="SendAlerts" OnClick="btnSendAlertEmail_Click"/>
            </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

jquery

function ViewModelPopup2() {
            $("#ViewModalPopupDiv2").dialog({
                scrollable: true,
                width: 800,
                modal: true
            });
        }

aspx.cs

protected void btnSendAlertEmail_Click(object sender, EventArgs e)
        {

            // Code to send email

        }

protected void btnConfigureAlerts_Click(object sender, EventArgs e)
        {

        ScriptManager.RegisterStartupScript
                       (this, this.GetType(), "callScriptFunction", "ViewModelPopup2();", true);
        }
    }

Please let me know what I need to do , to trigger the server control events .

4
  • Shouldn't your onClick event have btnConfigureAlerts_Click()? Why don't you just use a normal html button if you are just going to call the javascript function? Commented Sep 10, 2013 at 21:50
  • I believe she is wanting to trigger the code behind from the button inside the jquery dialog. I think your button ID needs to be "btnConfigureAlerts". Commented Sep 10, 2013 at 21:54
  • Check your console for javascript errors. Commented Sep 10, 2013 at 21:57
  • I apologize for the confusion, btnConfigureAlerts and btnSendAlertEmail are two different buttons Commented Sep 10, 2013 at 21:59

2 Answers 2

25

I also had this problem with asp.net buttons and jQuery UI Dialog. To solve it you need to set in your aspnet button the tag UseSubmitBehavior to false.

If UseSubmitBehavior attribute is set to true (this is the default value), the button will use the browser's submit mechanism (and jQuery Dialog UI is manipulating it), if UseSubmitBehavior is set to false, the button will use a client-side script that asp.net framework includes in the page to post to the form.

So your HTML should be like this :

<div id='one'>
<asp:LinkButton ID="ConfigureAlerts" OnClick="btnConfigureAlerts_Click" runat="server">Configure Alerts</asp:LinkButton>
</div>
<div id="ViewModalPopupDiv2">
        <asp:UpdatePanel ID="UpdatePanel3" runat="server">
            <ContentTemplate>
            <asp:Panel ID="Panel2" runat="server" HorizontalAlign="left" ScrollBars="Auto">
            <asp:Button ID="btnGetLogs" runat="server" Text="SendAlerts" OnClick="btnSendAlertEmail_Click" UseSubmitBehavior="false" />
            </asp:Panel>
            </ContentTemplate>
        </asp:UpdatePanel>
    </div>

More details at http://msdn.microsoft.com/library/system.web.ui.webcontrols.button.usesubmitbehavior.aspx

Sign up to request clarification or add additional context in comments.

6 Comments

I just edited my code. Please check it , I have two buttons, and I think the button click event I am using is correct
@Agent007 ok, I added a example in my answer. Hope it help you.
Hey Thanks This works ! Can you also tell me how I can use a drop downlist within jquery dialog. The DropdownList index is not changing currently.
+1 i had same problem and problem is solved by u..thanks @GuilhermeJSantos
Sure enough. I changed my aspx page to a user control, thus eliminating the jQuery load(), and then it worked fine with UseSubmitBehavior="false".
|
4

This is the classic, thanks for moving my dialog jQuery, question.

jQuery UI for some reason moves your dialog code to the bottom of the html markup, outside of your form tag. You need to move the dialog back into the form with some more jQuery:

dlg.parent().appendTo(jQuery('form:first'));

where dlg is your jQuery.UI dialog object.

        var dlg = $("#ViewModalPopupDiv2").dialog({
            scrollable: true,
            width: 800,
            modal: true
        });
        dlg.parent().appendTo(jQuery('form:first'));

That should get things working for you again. Cheers!

If that doesn't work, try doing that in the open event:

open: function(type,data) { $(this).parent().appendTo("form"); }

2 Comments

Hey TombMedia ! Thank you ! Somehow the solution doesnt work . I am wrapping the above code in a function called function ViewModalPopup2() . Do you think that would be causing the problem ?
No that wouldn't be the problem at all. Glad to see you got this sorted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.