Click here to Skip to main content
15,879,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to just print an aler msg when button1 is clicked.But this not work..whts the error?

C#
$(document).ready(function ()
{
  $("#Button1").click(function ()
{


    alert("hi");
 });


I used the following button

<asp:Button ID="Button1" runat="server" Text="Button" />
Posted
Comments
Shemeemsha (ഷെമീംഷ) 19-Sep-14 2:52am    
And put the alert after the document.ready() and check the Jquery is loading or not?
In console past $("#Button1") check the element is loading properly or not>>
Can you debug in your console window and refer the issue here??

Try this
ASP.NET
<asp:button id="Button1" runat="server" text="Button"  ClientIDMode="Static" /> 


If you want to use the ID of the button as "Button1" in jquery then you need to set the ClientIDMode to static.
 
Share this answer
 
v4
Comments
Shemeemsha (ഷെമീംഷ) 19-Sep-14 2:56am    
But he is not using the button name..He using id..Then what is the need for ClientIDMode="Static"
ChauhanAjay 19-Sep-14 2:59am    
Thanks for correcting me I will change that to ID
Nijisha Kc 19-Sep-14 3:02am    
Thaks all.. Now My problem solved.
I just added this line...

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js" type="text/javascript"></script>
You didnt use onclick event

ASP.NET
<asp:Button id="Button1" Text="Click me!" runat="server" OnClick="submit" />
 
Share this answer
 
v2
Comments
Gihan Liyanage 19-Sep-14 2:06am    
I am so sorry about the previous answer. I didnt see the asp code. Try this.
Nijisha Kc 19-Sep-14 2:34am    
But I didnt gave a name like submit to the function...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900