checkbox onclientclick event not firing

Posted by Bhuvana under JavaScript on 11/6/2013 | Points: 10 | Views : 6257 | Status : [Member] | Replies : 5
Dear,
I given my code as below checkbox onclientclick event was not firing any one help me

<asp:DataList ID="dtlThumbNailView" runat="server" RepeatColumns="1" Width="100%"
OnItemCommand="dtlThumbNailView_ItemCommand" OnItemDataBound="dtlThumbNailView_ItemDataBound">
<ItemTemplate>
<table>
<tr>
<td align="left">
<asp:Label ID="lblDesc" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>'
Width="200px"></asp:Label>
</td>
</tr><tr>
<td align="left">
<asp:CheckBox ID="cbxCompare" runat="server" OnClientClick='<%# string.Format("javascript:return chkCompare(\"{0}\")", Eval("Name")) %>' />
<asp:Label ID="lblComPare" runat="server" Enabled="false" Text=" Add to Compare"></asp:Label>
</td>
</tr>
</table>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

Thanks & Regards
Bhuvana



Responses

Posted by: Learningtorise on: 11/6/2013 [Member] Starter | Points: 25

Up
0
Down
Y written so Complicated,
OnClientClick='<%# string.Format("javascript:return chkCompare(\"{0}\")", Eval("Name")) %>'

Could have easily done with
OnClientClick='javascript:return chkCompare('Eval("Name")')'


http://hashtagakash.wordpress.com/

Bhuvana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Learningtorise on: 11/6/2013 [Member] Starter | Points: 25

Up
0
Down
Also, u can test your code by simply:
OnClientClick='javascript:alert('Test');'


http://hashtagakash.wordpress.com/

Bhuvana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 11/6/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
Remove your string.Format and use like this

OnClientClicking='<%# "chkCompare("+ Eval("Name") + ");" %>'


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Bhuvana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Allemahesh on: 11/6/2013 [Member] [MVP] Silver | Points: 25

Up
0
Down
You can also use the below one:-

<asp:CheckBox ID="cbxCompare" runat="server" OnClientClick='<%# Eval("Name","javascript:chkCompare({0});") %>' /> 


Happy Coding,
If it helps you or directs U towards the solution, MARK IT AS ANSWER

Bhuvana, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: vishalneeraj-24503 on: 11/6/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi,
You can simply give OnClientClick = "JavaScript:chkCompare(Eval('Name') return false;"

Or you can write on Datalist ItenDataBound event as follows :-
protected void dtlThumbNailView_ItemDataBound()
{
//find check box (cbxCompare) and Label(lblDesc) Ids
CheckBox cbxCompare = e.Item.FindControl("cbxCompare") as CheckBox;
Label lblDesc = e.Item.FindControl("lblDesc") as Label;

if(cbxCompare!=null && lblDesc!=null)
{
cbxCompare.OnClientClick = String.Format("chkCompare('{0}');return false;", lblDesc.Text);
}
}

Bhuvana, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response