checkbox inside an update panel does not get its state
I have 2 checkboxes inside an Updatepanel:
<asp:UpdatePanel>
<asp:CheckBox CssClass="checkboxDivE"/>
<asp:CheckBox CssClass="checkboxDivE"/>
<asp:UpdatePanel>
in js, jquery:
$('.checkboxDivE').live('click', function (e) {
alert($(this).is(':checked')); // always giving false result
});
markup:
<span class="checkboxDivE" title="Export a trip"><input id="ctl00_ContentPlaceHolder1_GridView_Trips_ctl02_checkboxDivE" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView_Trips$ctl02$checkboxDivE"></span>
<span class="checkboxDivE" title="Export a trip"><input id="ctl00_ContentPlaceHolder1_GridView_Trips_ctl03_checkb开发者_如何学运维oxDivE" type="checkbox" name="ctl00$ContentPlaceHolder1$GridView_Trips$ctl03$checkboxDivE"></span>
Whenever I check or uncheck the checkbox, the result is always false?
I have spent hours for finding a solution but I could not! is it a problem with jquery inside an updatePanel?
If you look at your markup, you'll notice that the ID of your checkbox is actually ctl00_ContentPlaceHolder1_GridView_Trips_ctl03_CheckBoxExportTour
and the class you are trying to grab - checkboxDivE
- belongs to the span.
You just need to change your selector.
It should be used like this: http://jsfiddle.net/fvVAy/
Maybe you're using a class selector where you should be using a name selector. If the jsfiddle doesn't help, try uploading checkbox markup.
精彩评论