Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1430
  • Last Modified:

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');");
            }

Open in new window

0
tbaseflug
Asked:
tbaseflug
  • 4
  • 3
1 Solution
 
ajitha75Commented:
The code is correct. Maybe when the for loop is executed, there are no items in checkboxlist.
0
 
Chandan_GowdaCommented:
once the page is completely rendered,view the source of the web page.and cross check onclick attribute for checkbox's .
0
 
tbaseflugAuthor Commented:
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');");
        } 

Open in new window

0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

 
ajitha75Commented:
Why in OnDataBound. You should do it in Page load itself.... after calling DataBind()

0
 
tbaseflugAuthor Commented:
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');");
            }
0
 
ajitha75Commented:
can you paste your complete code here?
0
 
tbaseflugAuthor Commented:
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  >

Open in new window

0
 
ajitha75Commented:
You are not setting datasource.. then why do databind?
also if it is a static list, then you can add the onclick directly in the html code. why loop thru in the code behind?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now