View Full Version : [CLOSED] CheckBoxGroup initial state

Nov 06, 2012, 4:37 AM
Below is a sample I put together to discuss the CheckBoxGroup CheckItems. After your helped in the previous thread (http://forums.ext.net/showthread.php?21792), I now have the following question.

If I push the 'Get Count' button the answer is 0
If I select the Calendar button to show the years selected and then push the 'Get Count' button the answer is 1.

Shouldn't the initial answer also be 1 instead of 0?

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
protected void GetCheckedItemsCount(object sender, DirectEventArgs e)
CheckboxGroup group = X.GetCmp<CheckboxGroup>("CheckboxGroup1");
for (var i = 0; i < group.CheckedItems.Count; i++)
X.Msg.Alert("Item Selected", group.CheckedItems[i]).Show();
X.Msg.Alert("DirectEvent", group.CheckedItems.Count).Show();

protected void CheckBoxChange(object sender, DirectEventArgs e)
CheckboxGroup group = X.GetCmp<CheckboxGroup>("CheckboxGroup1");
string strYears = "";
for (var i = 0; i < group.CheckedItems.Count; i++)
strYears = strYears + group.CheckedItems[i].RawValue + " ";
X.Msg.Alert("CheckBox Change", strYears).Show();

<!DOCTYPE html>
<head id="Head1" runat="server">
<title>Ext.NET v2 Example</title>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Panel runat="server" Title="Charts" Icon="ChartBar" Region="South" Height="240"
Split="true" Collapsible="true" Layout="BorderLayout">
<ext:Toolbar runat="server" Dock="Left" Vertical="true">
<ext:Button runat="server" ToolTip="Years" Icon="Calendar" ArrowAlign="Right" MenuAlign="tl-tr">
<ext:Menu runat="server" Title="Request Years" TitleAlign="Center" ShowSeparator="false"
<ext:CheckboxGroup ID="CheckboxGroup1" runat="server" OnDirectChange="CheckBoxChange"
<ext:Checkbox runat="server" Name="year1" BoxLabel="2012" InputValue="2012" Checked="true" />
<ext:Checkbox runat="server" Name="year2" BoxLabel="2011" InputValue="2011" />
<ext:Checkbox runat="server" Name="year3" BoxLabel="2010" InputValue="2010" />
<ext:Checkbox runat="server" Name="year4" BoxLabel="2009" InputValue="2009" />
<ext:Checkbox runat="server" Name="year5" BoxLabel="2008" InputValue="2008" />
<ext:Checkbox runat="server" Name="year6" BoxLabel="2007" InputValue="2007" />
<ext:MenuSeparator runat="server" />
<ext:MenuSeparator runat="server" />
<ext:Button runat="server" Text="Select All">
<Click Handler="#{CheckboxGroup1}.setValue({ year: true })" />
<ext:Button ID="Button1" runat="server" Text="Deselect All">
<Click Handler="#{CheckboxGroup1}.setValue({})" />
<ext:Button runat="server" Text="Get Count" OnDirectClick="GetCheckedItemsCount" />

Nov 06, 2012, 5:56 AM
Hi Chris,

A problem is a fact that a Button's Menu and, respectively, its items (a CheckboxGroup in your case) are not rendered by default. It is rendered on click.

Therefore no submit before click.

You could send a required data via a DirectEvent's ExtraParams collection. But I would prefer to use this trick to force rendering.

<AfterRender Handler="this.showMenu(); this.hideMenu();" />

It is a Button's listener.

Nov 06, 2012, 7:20 AM
You got me around an issue again. Thank you. Go ahead and close this thread.