ND's
ND's

Reputation: 2215

how to acees asp.net button or controls in jquery

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

Answers (2)

Dan Lister
Dan Lister

Reputation: 2583

Try...

$("#<%= btn.ClientID %>").click(function () {
});

Upvotes: 1

Adil
Adil

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

Related Questions