1

I have a image on which I am opening an alert. On confirmation in this alert, I am triggering the server click event. Here is a quick piece of code.

function showConfirmMessage() {
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover this data!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, delete it!",
        closeOnConfirm: true
    }, function () {
        document.getElementById("btnDeleteUser").click();
    });
    return false;
}

Here is the code of the button.

 <asp:Button runat="server" ID="btnDeleteUser" ClientIDMode="Static" class="hidden" type="submit" OnClick="btnDeleteUser_Click" />

document.getElementById("btnDeleteUser").click(); this line is called successfully when I click confirm in the alert box. But the actual event is never fired. The page is never submitted back to the server.

I am unable to figure out what is missing here. There are no errors in the console. Application never reaches the server side function.

1

1 Answer 1

1

you should use it:

document.getElementById("<%= btnDeleteUser.ClientID %>").click();
2
  • we can't use above code because i am using btnDeleteUser inside javascript file. Jul 24, 2018 at 4:29
  • aspx: window.DeleteUserClientId = "<%= btnDeleteUser.ClientID %>"; js: document.getElementById(window.DeleteUserClientId).click(); Jul 24, 2018 at 4:31

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.