Reputation: 38663
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?
Upvotes: 0
Views: 67
Reputation: 3314
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>
Upvotes: 1
Reputation: 17614
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>
Upvotes: 1
Reputation: 995
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>
Upvotes: 1