| | |
CheckboxList ListItem Onclick not firing
Please support our ASP.NET advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jun 2006
Posts: 11
Reputation:
Solved Threads: 0
I am using .Net 2 in Vs 2008 and I am trying to get the onclick event for a checkox to fire when clicked. Unfortunately it is not firing. I can see the code is added to the checkboxs html.
This is the checkboxlist:
this is the code that set the onclick attribute:
The checkboxlist is databound and within a databound repeater.
Any ideas?
Thanks!
This is the checkboxlist:
ASP.NET Syntax (Toggle Plain Text)
<asp:CheckBoxList runat="server" ID="chkSides" RepeatColumns="3" RepeatDirection="Horizontal" DataValueField="ItemNo" DataTextField="ShortName" BackColor="White" OnDataBound="chkSides_OnItemDataBound" ></asp:CheckBoxList>
this is the code that set the onclick attribute:
ASP.NET Syntax (Toggle Plain Text)
protected void chkSides_OnItemDataBound(object sender, EventArgs e) { CheckBoxList chkSides = (CheckBoxList)sender; foreach (ListItem listitem in chkSides.Items) { listitem.Attributes.Add("onclick", "alert('hey');"); } }
The checkboxlist is databound and within a databound repeater.
Any ideas?
Thanks!
•
•
Join Date: Jun 2006
Posts: 11
Reputation:
Solved Threads: 0
0
#4 Oct 27th, 2009
I forgot to mention that the repeater and checkboxlist are within an ajax updatepanel. So the problem seems to be that on the partial post back the OnItemDataBound isn't being fired. So the question now becomes how can I set the attribute in such a way that it is persisted across post backs?
•
•
Join Date: Jun 2009
Posts: 452
Reputation:
Solved Threads: 82
0
#5 Oct 27th, 2009
Putting the CheckBoxList control inside a UpdatePanel control does not make this problem.
The CheckBoxList is implemented a collection of ListItems.
Attributes added to a ListItem control don't get rendered during postback.
Actually it is a bug in ASP.NET.
Refer the following links to know more about on this bug.
http://unboxedsolutions.com/sean/arc...05/04/213.aspx
http://support.microsoft.com/default...;en-us;Q309338
http://aspnet.4guysfromrolla.com/articles/091405-1.aspx
To work around this issue, you need to add attributes to ListItem collection in the Page PreRender event instead of DataBound event.
Try this code.
The CheckBoxList is implemented a collection of ListItems.
Attributes added to a ListItem control don't get rendered during postback.
Actually it is a bug in ASP.NET.
Refer the following links to know more about on this bug.
http://unboxedsolutions.com/sean/arc...05/04/213.aspx
http://support.microsoft.com/default...;en-us;Q309338
http://aspnet.4guysfromrolla.com/articles/091405-1.aspx
To work around this issue, you need to add attributes to ListItem collection in the Page PreRender event instead of DataBound event.
Try this code.
ASP.NET Syntax (Toggle Plain Text)
protected void Page_PreRender(object sender, EventArgs e) { foreach (ListItem listitem in chkSides.Items) { listitem.Attributes.Add("onclick", "alert('hey');"); } }
Last edited by Ramesh S; Oct 27th, 2009 at 6:30 am.
•
•
Join Date: Jun 2006
Posts: 11
Reputation:
Solved Threads: 0
0
#6 Oct 27th, 2009
•
•
•
•
Putting the CheckBoxList control inside a UpdatePanel control does not make this problem.
The CheckBoxList is implemented a collection of ListItems.
Attributes added to a ListItem control don't get rendered during postback.
Actually it is a bug in ASP.NET.
Refer the following links to know more about on this bug.
http://unboxedsolutions.com/sean/arc...05/04/213.aspx
http://support.microsoft.com/default...;en-us;Q309338
http://aspnet.4guysfromrolla.com/articles/091405-1.aspx
To work around this issue, you need to add attributes to ListItem collection in the Page PreRender event instead of DataBound event.
Try this code.
ASP.NET Syntax (Toggle Plain Text)
protected void Page_PreRender(object sender, EventArgs e) { foreach (ListItem listitem in chkSides.Items) { listitem.Attributes.Add("onclick", "alert('hey');"); } }
In any case I found a way to stop the partial post back so I don't have this problem now.
Thanks for the help
•
•
Join Date: Jun 2009
Posts: 452
Reputation:
Solved Threads: 82
0
#7 Oct 27th, 2009
From your first post, it seems that you put the ChecBoxList control inside a Repeater control.
If so, you can try this code.
Anyway, you found a solution by yourself.
Mark this thread as solved/
If so, you can try this code.
ASP.NET Syntax (Toggle Plain Text)
protected void Page_PreRender(object sender, EventArgs e) { foreach (RepeaterItem ritem in Repeater1.Items) { CheckBoxList chkList = ritem.FindControl("CheckBoxList1") as CheckBoxList; foreach (ListItem listitem in chkList.Items) { listitem.Attributes.Add("onclick", "alert('hey');"); } } }
Anyway, you found a solution by yourself.
Mark this thread as solved/
![]() |
Similar Threads
- Sending value of checkboxes to new page? (ASP.NET)
- checkboxlist (ASP.NET)
- SelectedIndexChanged not firing for dropdownlist (ASP.NET)
- Help with Swapping Images onclick (JavaScript / DHTML / AJAX)
- Checkbox (ASP.NET)
- Session variable (ASP.NET)
- changing from onclick to onsubmit? possible? (JavaScript / DHTML / AJAX)
- Regarding ListItem Class (ASP.NET)
- Newbie Needs Help with this ASPX (ASP.NET)
Other Threads in the ASP.NET Forum
- Previous Thread: does C# Window Service supports Browser_DocumentCompleted event of Web browser?
- Next Thread: chat room in asp.net
Views: 573 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for ASP.NET
.net 2.0 activexcontrol advice ajax anathor application asp asp.net bc30451 bottomasp.net browser businesslogiclayer button c# c#gridviewcolumn chat checkbox child click commonfunctions compatible confirmationcodegeneration content contenttype courier css database datagrid datagridview datagridviewcheckbox datalist deadlock development dgv dropdown dropdownmenu edit expose feedback flash flv form formatdecimal forms formview google grid gridview homeedition hosting identity iframe iis index javascript jquery list menu migration mono mssql multistepregistration object objects order problem ratings refer rotatepage save search security serializesmo.table session silverlight smartcard software sql sqlserver2005 suse textbox tracking typeof unauthorized update validation vb vb.net video view virtualdirectory vista visual-studio visualstudio web webarchitecture webdevelopemnt xml youareanotmemberofthedebuggerusers





