0

Am trying to fire a jquery in a asp.net button.It is not getting triggered.What's going to wrong ?

//Code

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src ="Scripts/jquery-1.4.1.js"></script>
<script type ="text/javascript">
  $(document.ready(function(){
       $("#<%=Button1.ClientID %>").click(function () {
                 showalert('HTML Button Clicked');
       });
  });

  function showalert(btnText) {
      alert(btnText)
  } 
</script>

</head>
<body>
   <form id="form1" runat="server">
     <div>
        <asp:Button ID="Button1" runat="server" Height="41px" 
           style="margin-left: 340px; margin-top: 197px" 
          Text="Button" Width="147px"/>
     </div>
  </form>
</body>
</html>

Can some one help me?

3
  • 1
    $(document) -> closing Parentheses is missing Commented Mar 29, 2013 at 6:16
  • Update your jquery version also if possible Commented Mar 29, 2013 at 6:21
  • It is $(document).ready(function() { //...}); Commented Mar 29, 2013 at 6:26

3 Answers 3

1

your document ready syntax is wrong . Try this code

<script type ="text/javascript">

    $(document).ready(function () {
        $("#<%=Button1.ClientID %>").click(function () {

            showalert('HTML Button Clicked');
        });
    });
  function showalert(btnText) {
      alert(btnText)
  } 
</script>

</head>
<body>
   <form id="form1" runat="server">
     <div>
        <asp:Button ID="Button1" runat="server" Height="41px" 
           style="margin-left: 340px; margin-top: 197px" 
          Text="Button" Width="147px"/>
     </div>
  </form>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

1

You are missing right ) in document.ready

<script type ="text/javascript">
  $(document).ready(function(){
       $("#<%=Button1.ClientID %>").click(function (event) {
             showalert('HTML Button Clicked');
             event.preventDefault();//don't forgot this
       });
  });

 function showalert(btnText) {
    alert(btnText)

  } 
</script>

Comments

1

Try This:

  <asp:Button ID="Button1" runat="server" Height="41px" OnClientClick="function_name();" 
             style="margin-left: 340px; margin-top: 197px" Text="Button" Width="147px"/>

In script define the function function_name():

<script type ="text/javascript">

         function function_name() {
             //what ever you want.
            } 
</script>

Comments

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.