tbaseflug
asked on
Checkboxlist item onclick JS
I am tryign everythign to set an onclick JS event for a checkboxlist item - wityh nothing happening?
ULCheckBoxList1.DataBind();
foreach (ListItem li in ULCheckBoxList1.Items)
{
li.Attributes.Add("onclick", "javascript:alert('test');");
}
The code is correct. Maybe when the for loop is executed, there are no items in checkboxlist.
once the page is completely rendered,view the source of the web page.and cross check onclick attribute for checkbox's .
ASKER
OK - weird - I am databinding my cbl in the page load and then setting the OnDataBound to the below - but when I view the rendered source - nothing is there?
foreach (ListItem li in ULCheckBoxList1.Items)
{
li.Attributes.Add("onclick", "javascript:alert('test');");
}
Why in OnDataBound. You should do it in Page load itself.... after calling DataBind()
ASKER
even when I put it in the page load - I do not see it in the rendered html
ULCheckBoxList2.DataBind() ;
foreach (ListItem li in ULCheckBoxList1.Items)
{
li.Attributes.Add("onclick ", "javascript:alert('test'); ");
}
ULCheckBoxList2.DataBind()
foreach (ListItem li in ULCheckBoxList1.Items)
{
li.Attributes.Add("onclick
}
can you paste your complete code here?
ASKER
besides the above - this is it
<asp:CheckBoxList ID="ULCheckBoxList1" runat="server" CellPadding="0" CellSpacing="0"
CssClass="colorCheck">
<asp:ListItem id="aa" >ICD9 Codes (2007 updates included): </asp:ListItem>
</asp:CheckBoxList >
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.