Reputation: 121
$(function ()
{
$('#btnnext').click(function ()
{
alert("Hello after click event");
});
});
And the code for button as:
<asp:Button ID="btnnext" runat="server" CssClass="BStyle" OnClick="btnnext_Click" Text="Save" />
I have place Button control in update panel control and also have used master.. page
Upvotes: 1
Views: 113
Reputation: 1235
You can use your button ID or your Css class as selector
ID selector
$('<%#btnnext.ClientID%>').click(function ()
{
alert("Hello after click event");
});
Class selector
$('.BStyle').click(function ()
{
alert("Hello after click event");
});
Upvotes: 0
Reputation: 9031
Look at what ASP.net generates (view source on your webpage).
ASP.NET webforms generate another ID for the frontend ID then what you are saying to asp:Button. my advice is to either bind the click on a cssClass instead or if you still want to bind it with an id you need to use [id$="_btnnext"]
as a selector.
$(function () {
$('[id$="_btnnext"]').click(function () {
alert("Hello after click event");
});
});
Upvotes: 1
Reputation: 41
$('#<%=btnnext.ClientID%>').click(function ()
{
alert("Hello after click event");
});
Another way would be to use OnClientClick
attribute
<asp:Button ID="btnnext" runat="server" CssClass="BStyle" OnClick="btnnext_Click" OnClientClick="MyFunctionName()" Text="Save" />
<script>
function MyFunctionName(){
alert('test');
}
</script>
Upvotes: 3
Reputation: 10275
try this:
You can Use ClientID
to Get AcutalID Generated by ASP.net
$('<%#btnnext.ClientID%>').click(function ()
{
alert("Hello after click event");
});
Upvotes: 2
Reputation: 9060
Try this, using .on
function :
$(function()
{
$('#btnnext').on('click',function()
{
alert("Hello after click event");
});
});
Upvotes: -1