Reputation: 2215
How can I access ASP.Net buttons or controls using jQuery in the following example?
window.onload = body_load;
function body_load() {
var btn = document.getElementById('<%=btn.ClientID %>');
}
$("#btn").click(function () {
}
<asp:Button ID="btn" Width="134px" runat="server" Text="Fix" CssClass="cssbutton" />
Upvotes: 1
Views: 60
Reputation: 148110
You can bind event with asp.net button using jquery on document ready like this.
$(function(){
$('#<%=btn.ClientID %>').click(function() {
alert("clicked");
return false; // returning false will stop from postback to server, true will cause postback
});
});
Upvotes: 3