Question

First of all I should mention that I spend whole day on searching and can't figure out whats wrong with my code and why it doesn't work ...

I need a modal dialog for confirmation in my code , so I use this jQuery modal dialog : JQuery Confirm

What I need is to embed this functionality with a <asp:Button>...

My problem is that when I click on the button the dialog popup but the yes/no buttons doesn't work and both just disappear the dialog.

Also I use code below but __doPostBack() didn't do anything at all but it runs simple js codes like alert('') perfectly:

$("#complexConfirm").confirm({
     title: "Redirect confirmation",
     text: "This is very dangerous, you shouldn't do it! Are you really really sure?",
     confirm: function (button) {
         __doPostBack('complexConfirm', 'OnClick');
     },
     cancel: function (button) {
         return false;
     },
     confirmButton: "Yes",
     cancelButton: "No"
});

I search and dialog cause element comes outside of the form element so I should bring it back to the form but I don't know how I try below code and it doesn't

$("#editEventModal").parent().appendTo(jQuery("form:first"));

Another probelm is I try to postback with javascript event without the dialog box, I use 2 button one for calling javascript and another for calling that , but when I use __doPostBack it refresh the page but doesn't comes to my button event in the code-behind, I try several ways to calling button onClick event but it just refresh the page and doesn't call my butoon OnClick Mehtod !!!

The buttons declaration are like this :

<asp:Button ID="complexConfirm" ClientIDMode="Static" runat="server" OnClick="TestBTN_Click" Text="Test" />
<asp:Button ID="checkit" ClientIDMode="Static" runat="server" OnClientClick="__doPostBack('<%=complexConfirm.UniqueID%>', '');" Text="CHECK" />

What should I do for these two problems ?

I search a lot and non of the solutions worked for me !!!

I will appreciate any solution, thank you.

Was it helpful?

Solution

Without knowing the declaration of your asp:button, here is my best guess.

You need to use the uniqueID of the button, the button's "name" attribute, not it's ID.

__doPostBack('<%=complexConfirm.UniqueID%>', '');

also, since its a button, you don't actually need to specify OnClick

EDIT: I created a working example demonstrating what i think you're trying to accomplish. You can tailor this to your jQuery confirm as needed.

aspx:

<asp:Button ID="btnTest1" runat="server" Text="Test1" OnClick="btnTest1_Click" />

javascript:

<script>
    $('#<%=btnTest1.ClientID%>').confirm({
        text: "This is very dangerous, you shouldn't do it! Are you really really sure?",
        title: "Confirmation required",
        confirm: function (button) {
            // do something
            __doPostBack('<%= btnTest1.UniqueID%>', '');
        },
        cancel: function (button) {
            // do something
        },
        confirmButton: "Yes I am",
        cancelButton: "No",
        post: true
    });
</script>

code behind:

protected void btnTest1_Click(object sender, EventArgs e)
{
    Response.Write("You clicked YES");
}

I think part of the problem was that you're event name wasn't named with the name of your button. If using autoEventWireup, which I think you are, then your event wont trigger because it can't find an event with a matching name.

So, first thing I did was eliminate the StaticClientID. you can still use jquery with asp.net generated IDs. Then I made sure the event was named btnTest1_Click because the name of the button is btnTest1

I'm not sure why you needed the other button, because it seems all you're trying to do is confirm before the button submits.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top