Shrivallabh
Shrivallabh

Reputation: 2893

button click event in jquery is not triggered for asp button

 <asp:Button runat="server" CssClass="btn btn-primary btn-group-lg" ID="btnSubmit" Text="Sign in" OnClick="btnSubmit_Click" />

This is my button. I have a javascript file <script src="Scripts/jsFile.js"></script> Where i have written below code

$(document).ready(function () {
    $('#divMain').hide().fadeIn(2000)

    $(document).on("click", "#btnSubmit", function (e) {
        alert('The element myID is clicked');
    });
});

fadeIn functionality works however click is not triggered. I need to do something else??

Upvotes: 0

Views: 88

Answers (1)

Mahesh
Mahesh

Reputation: 8892

Possible issue is your jquery script is unable to find the id thats why event is not firing.

Try using the

 '<%=btnSubmit.ClientID%>' 

This will work very fast as it will use native document.getElementById. in your selector.
As server control id generation pattern is something you dont want to dependent on.

OR

As mentioned by @Kartikey You can set the ClientIDMode = Static of #btnSubmit button

Upvotes: 1

Related Questions