reference to asp.net button not working
Hi all,
I am new to jquery so sorry for the silly question.
I am not able to make a working reference to buttons inside an asp.net page
Here is my page
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplicationTest._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<script src="Scripts/jquery-1.7-vsdoc.js" type="text/javascript"></script>
<script src="Scripts/jquery-1.7.js" type="text/javascript"></script>
<script src="Scripts/custom.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$('#<%=ButtonTest.ClientID%>').click(function (event) {
alert("I am ready!");
});
});
</script>
<h2>
Welcome to ASP.NET!
</h2>
<p>
To learn more about ASP.NET visit <a href="http://www.asp.net" title="ASP.NET Website">www.asp.net</a>.
</p>
<p>
You can also find <a href="http://go.microsoft.com/fwlink/?LinkID=152368&clcid=0x409"
title="MSDN ASP.NET Docs">documentation on ASP.NET at MSDN</a>.
</p>
<asp:Button ID="Button1" runat="server" Text="Button1" />
<asp:Button ID="Button2" runat="server" Text="Button2" />
<asp:Button ID="ButtonTest" runat="server" Text="Test" />
<asp:Button ID="Button3" runat="server" Text="Button3"/>
</asp:Content>
perfectly working for ButtonTest but only with the shown syntax '#<%=ButtonTest.ClientID%>' and not with the simple ButtonTest as shown in some tutorials.
I have an external file of scripts that looks like this
jQuery(document).ready(function () {
$(document).ready(function(){
$('#<%=Button3.ClientID%>').click(function (event) {
alert("OK OK!");
});
});
$(document).ready(function () {
$("a").click(function () {
alert("Hello world!");
});
});
});
Where the alert for "any link" works perfectly while the alert for Button3 is never triggered.
In the tutorials I have always seen the button referred by their Id, but here it is not really working.
Any idea on the reason?
I tried to put return false as i have seen suggested in other posts, but without success.
The way for referring to all the buttons should be ":button", but again this does not work. Can you tell me where I am wrong and how to refer to all the buttons?
The last info I can provide is that I am running this on the debug mode of visualstudio 2010.
Any help is appreciated.
Thanks
stmod