0
 <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??

asked Feb 24, 2015 at 5:46
2
  • 1
    set ClientIDMode = Static of #btnSubmit button. Commented Feb 24, 2015 at 5:49
  • Put e.preventDefault (); just before the alert statement. Also you don't need OnClick="btnSubmit_Click" Commented Feb 24, 2015 at 5:56

1 Answer 1

1

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

answered Feb 24, 2015 at 5:47

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.