Home > Mobile >  Checkbox doesn't work on first click when checked by default
Checkbox doesn't work on first click when checked by default

Time:02-04

I have some checkboxes that doesn't work in first click when they are already checked by default.

What's happen is: When I click in te checked checkbox he fire Page_Load but doesn't fire OnCheckedChanged event and keep checked until I click again(after this all checkboxes start to work normally).

In the tests I made, I notice that if I keep the Panel witch include the checkboxes always visible this problem does not occur and if I remove the OnCheckedChanged event too

 <asp:UpdatePanel runat="server" ID="updApply">
    <ContentTemplate>
        <div >
            <div >
                <asp:Panel runat="server" ID="pnlApply">
                    <div >
                        <div >
                            <asp:Panel runat="server" ID="pnlAplicaDescontoEstabelecimento">
                                <div >
                                    <div >
                                        <div >
                                            <asp:CheckBox ID="cbxApply" runat="server" 
                                                onchange="loadUI();" 
                                                OnCheckedChanged="apply_CheckedChanged" 
                                                AutoPostBack="True" />
                                        </div>
                                    </div>
                                </div>                                                    
                            </asp:Panel>
                        </div>
                    </div>
                </asp:Panel>
            </div>
        </div>
    </ContentTemplate>
</asp:UpdatePanel>

I think it's important to say that in the code behind there are some functions that control whether the Panel is visible

Thanks!

CodePudding user response:

Instead of using visible, try setting the css style display:none. Visible removes the control fronlm the pages markup entirely during render and may remove it's persisted value from viewstate resulting in the event not recognizing the changed value.

Another possible solution would be explicitly setting the default checked value to guarantee it makes it into viewstate, though it checked should default to false per the MSD.

  • Related