Trying to fire a jscript function when clicking on Checkbox

ninel

Active member
Joined
Mar 23, 2005
Messages
32
Location
Land O Lakes, Florida
Programming Experience
3-5
I have the following code:
Code:
<table cellSpacing="1" cellPadding="1" width="100%" border="0">
<TR>
<td align="center" width="100%"><asp:datagrid id="grdResults" runat="server" Height="50px" Font-Names="Tahoma" Width="600px" Font-Size="XX-Small"
PageSize="1" CellPadding="1" AutoGenerateColumns="False" BorderColor="Silver" BorderStyle="Solid" CellSpacing="1" HorizontalAlign="Center"
ForeColor="Black">
<HeaderStyle Font-Bold="True"></HeaderStyle>
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox ID ="checkAll" Runat="server" onclick="selectAll();" text="SELECT ALL" ></asp:CheckBox>
</ItemTemplate>
<ItemTemplate>
<input type="checkbox" ID="chkSelect" runat="server"></asp:CheckBox>
</ItemTemplate>

</asp:TemplateColumn>
<asp:TemplateColumn>
<HeaderTemplate>
ID
</HeaderTemplate>
<ItemTemplate>
<asp:Label ID="lblDetailId" text='<%# DataBinder.eval (Container.dataitem, "itmPunchtimeId")%>' Runat="server">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="sAgentId" HeaderText="AgentId"></asp:BoundColumn>
<asp:BoundColumn DataField="sLastName" HeaderText="Last Name"></asp:BoundColumn>
<asp:BoundColumn DataField="sFirstName" HeaderText="First Name"></asp:BoundColumn>
<asp:BoundColumn DataField="sRawLogin" HeaderText="StartTime"></asp:BoundColumn>
<asp:BoundColumn DataField="sRawLogout" HeaderText="EndTime"></asp:BoundColumn>
</Columns>
</asp:datagrid></td>
<TD> </TD>
</TR>
<tr>
<td> </td>
</tr>
</table>​


I am trying to put an onclick event in the checkbox. I see many examples on the internet, but when I do it a red sqiggly line appears under the onclick.

When I move my mouse over it I get the message "Could not find any attribute 'onclick' of element 'checkbox'"

What am I doing wrong?
Thanks,
Ninel
 
There is already a click event for CheckBox. It is the CheckedChanged event. You can always put code here to handle when someone clicks your checkbox.

Still, if you want to put an 'onclick' event on the checkbox, you need to add it to the attributes collection for the checkbox. Something like this:

VB.NET:
CheckBox1.Attributes.Add("onclick", "return confirm('Are you sure?');")
Of course, this is for adding some kind of client side confirmation box, but you get the gist.

HTH

Blokz
 
hey ,
U just have to capture the checkbox in the ItemDataBound of the Grid and then by using that checkcheck.attribute.add("onClick","return getConfirm()") it will fire an java script for u..
 
Back
Top