Solved

Checkboxlist item onclick JS

Posted on 2008-06-10
8
1,423 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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
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 500 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
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 …

718 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