Click here to Skip to main content
15,892,737 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

I am using a Gridview with a colum of Buttons (btnDisable). I have set Clientidmode to static and call a function of JQuery. But the problem is that JQuery only allows first button of all pages in GridView to call click event.

JavaScript
$(function () {
        $("#btnDisable").click(function () {
            alert("Hello");
        });
    });

Button Code is

XML
<asp:Button ID="btnDisable" runat="server" style="border:1px solid red; background:Silver" clientidmode="Static" Text="Disable"/>


Need your help..

Thanks in advance.
Posted
Updated 27-Jun-12 2:10am
v2

Assign some css class name for example Cssclass="mybtnclass" to button and use cssclass name in following code

C#
$(function () {
$(".mybtnclass").click(function () {
alert("Hello");
});
});
 
Share this answer
 
Comments
Vikram Bhatt 27-Jun-12 13:24pm    
This is better solution.
hunerajamshed 28-Jun-12 1:57am    
that's Great!
Thanks.
problem solved in first try with your solution.
as I am new to JQuery. I don't understand why it was not working with ID attribute. as I set clientidmode to static?
member60 28-Jun-12 7:12am    
my 4! actuaully it deserves 5 but i clicked for 4 in hurry.Hope you never mind.
Try to add the function in the button like this

JavaScript
function f()
{
   alert("Hello");
}


then add this to the button

ASP.NET
<asp:button id="btnDisable" onclientclick="f();" runat="server" style="border:1px solid red; background:Silver" clientidmode="Static" text="Disable" xmlns:asp="#unknown" />


Best Regards
Ahmed Assaf
eBusiness Developer
 
Share this answer
 
Comments
hunerajamshed 28-Jun-12 1:59am    
As I had to do that with JQuery above answer was helpful.
Thanks for replying

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900