Solved

Checkboxlist item onclick JS

Posted on 2008-06-10
8
1,418 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
  • 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
 
LVL 14

Expert Comment

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

0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

707 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now