开发者

CheckBox CheckedChanged Event without autopostback

开发者 https://www.devze.com 2022-12-24 14:10 出处:网络
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 t

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
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消