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();
Sign up to request clarification or add additional context in comments.

2 Comments

we can't use above code because i am using btnDeleteUser inside javascript file.
aspx: window.DeleteUserClientId = "<%= btnDeleteUser.ClientID %>"; js: document.getElementById(window.DeleteUserClientId).click();

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.