The CheckedChanged event of a checkbox fires upon autopostback. Is there a way to fire that e开发者_开发百科vent with autopostback set to false?
if you want to fire the event without telling the user that you have made a round trip to the server you can fire the event by ajax
<asp:ScriptManager ID="ScriptManager2" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:CheckBox runat="server" ID="cb" oncheckedchanged="cb_CheckedChanged">
</asp:CheckBox>
</ContentTemplate>
</asp:UpdatePanel>
By a manual postback.
Seriously, how could an event fire without posting back?
You can't.
The OnCheckedChanged is a proprerty of CheckBok object
(Control) in ASP.NET.
To fire the javascript code you have to use OnClick="checkboxchanged(this);"
and check manually if the the value checked
was changed:
<asp:CheckBox runat="server" ID="cb" onclick="checkboxchanged(this);" />
function checkboxchanged( sender ) {
if ( sender.checked ) {
// clicked and checked
} else {
// clicked and unchecked
}
}
精彩评论