CheckboxGroup.CheckedItems returns a list of all checked items for all Checkbox Group controls on the page

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    CheckboxGroup.CheckedItems returns a list of all checked items for all Checkbox Group controls on the page

    Package versions:
    • Ext.NET: 1.7.0
    • Ext.NET.Utilities: 2.5.0


    I've come across an odd error that appears to be related to the latest version of the Ext.NET.Utilities Nuget package. We recently upgraded this package from v2.2.1 to v2.5. After doing this, we found that, if a page contains multiple CheckboxGroup controls, accessing the CheckedItems property of a particular control returns a list of all checked items for all CheckboxGroup controls on the page, not just the CheckboxGroup control currently being accessed. The following sample demonstrates this:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="CheckboxGroups.Web.Default" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" EnableViewState="false" AjaxViewStateMode="Disabled" RethrowAjaxExceptions="true" />
            <ext:Viewport ID="ViewportMain" runat="server" Layout="FitLayout">
                <Items>
                    <ext:FormPanel ID="FormPanelMain" runat="server" Frame="true" ButtonAlign="Center" AutoScroll="true">
                        <Items>
                            <ext:FieldSet runat="server" Title="Valid Arrival Days" Width="360" HideLabels="True">
                                <Items>
                                    <ext:CheckboxGroup ID="CheckboxGroupArrivalDays" runat="server" ColumnsWidths="48,48,48,48,48,48,48">
                                        <Items>
                                            <ext:Checkbox runat="server" Flag="1" BoxLabel="Mon" Checked="true" />
                                            <ext:Checkbox runat="server" Flag="2" BoxLabel="Tue" Checked="true" />
                                            <ext:Checkbox runat="server" Flag="4" BoxLabel="Wed" Checked="true" />
                                            <ext:Checkbox runat="server" Flag="8" BoxLabel="Thu" Checked="true" />
                                            <ext:Checkbox runat="server" Flag="16" BoxLabel="Fri" Checked="true" />
                                            <ext:Checkbox runat="server" Flag="32" BoxLabel="Sat" Checked="true" />
                                            <ext:Checkbox runat="server" Flag="64" BoxLabel="Sun" Checked="true" />
                                        </Items>
                                    </ext:CheckboxGroup>
                                </Items>
                            </ext:FieldSet>
                            <ext:FieldSet runat="server" Title="Not Valid for stays including" Width="360" HideLabels="True">
                                <Items>
                                    <ext:CheckboxGroup ID="CheckboxGroupInvalidDays" runat="server" ColumnsWidths="48,48,48,48,48,48,48">
                                        <Items>
                                            <ext:Checkbox runat="server" Flag="1" BoxLabel="Mon" />
                                            <ext:Checkbox runat="server" Flag="2" BoxLabel="Tue" />
                                            <ext:Checkbox runat="server" Flag="4" BoxLabel="Wed" />
                                            <ext:Checkbox runat="server" Flag="8" BoxLabel="Thu" />
                                            <ext:Checkbox runat="server" Flag="16" BoxLabel="Fri" />
                                            <ext:Checkbox runat="server" Flag="32" BoxLabel="Sat" />
                                            <ext:Checkbox runat="server" Flag="64" BoxLabel="Sun" />
                                        </Items>
                                    </ext:CheckboxGroup>
                                </Items>
                            </ext:FieldSet>
                        </Items>
                        <Buttons>
                            <ext:Button ID="ButtonSave" runat="server" Icon="Disk" Text="Save">
                                <DirectEvents>
                                    <Click OnEvent="SaveClick">
                                        <EventMask ShowMask="true" />
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                        </Buttons>
                    </ext:FormPanel>
                </Items>
            </ext:Viewport>
        </form>
    </body>
    </html>
    
    using System.Collections.Generic;
    using System.Linq;
    
    using Ext.Net;
    
    namespace CheckboxGroups.Web
    {
        public partial class Default : System.Web.UI.Page
        {
            protected void SaveClick(object sender, DirectEventArgs e)
            {
                X.MessageBox.Show(new MessageBoxConfig
                {
                    Message = $"Arrival Days: {ToCsv(CheckboxGroupArrivalDays.CheckedItems)}<br/>Invalid Days: {ToCsv(CheckboxGroupInvalidDays.CheckedItems)}",
                    Title = "Selected Items",
                    Buttons = MessageBox.Button.OK
                });
            }
    
            private static string ToCsv(IEnumerable<Checkbox> checkboxes)
            {
                return string.Join(",", checkboxes.Select(x => x.BoxLabel));
            }
        }
    }
    Last edited by plok77; Aug 31, 2023 at 4:15 PM.

Similar Threads

  1. [CLOSED] checkbox returns uncheck although checked in form
    By jstifel in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 30, 2015, 4:36 PM
  2. Replies: 3
    Last Post: Feb 06, 2015, 12:41 PM
  3. [CLOSED] CheckBoxGroup Items Checked from DirectEvent
    By osef in forum 2.x Legacy Premium Help
    Replies: 6
    Last Post: Apr 01, 2014, 7:26 PM
  4. [CLOSED] Get Checked items of checkbox group
    By mohan.bizbites in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Oct 21, 2013, 5:02 PM
  5. [CLOSED] CheckboxGroup Returns No CheckedItems
    By elisa in forum 2.x Legacy Premium Help
    Replies: 8
    Last Post: Sep 25, 2013, 3:17 PM

Posting Permissions