?
Solved

Checkboxlist item onclick JS

Posted on 2008-06-10
8
Medium Priority
?
1,426 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
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.

 
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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

650 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