?
Solved

Checkboxlist item onclick JS

Posted on 2008-06-10
8
Medium Priority
?
1,424 Views
Last Modified: 2012-06-27
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
Comment
Question by:tbaseflug
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:ajitha75
ID: 21756696
The code is correct. Maybe when the for loop is executed, there are no items in checkboxlist.
0
 
LVL 7

Expert Comment

by:Chandan_Gowda
ID: 21756732
once the page is completely rendered,view the source of the web page.and cross check onclick attribute for checkbox's .
0
 

Author Comment

by:tbaseflug
ID: 21758966
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:ajitha75
ID: 21759310
Why in OnDataBound. You should do it in Page load itself.... after calling DataBind()

0
 

Author Comment

by:tbaseflug
ID: 21759714
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
 
LVL 14

Expert Comment

by:ajitha75
ID: 21759906
can you paste your complete code here?
0
 

Author Comment

by:tbaseflug
ID: 21760034
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
 
LVL 14

Accepted Solution

by:
ajitha75 earned 2000 total points
ID: 21760095
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question