[OPEN] [#251] Dynamically created Checkbox not Checked

  1. #1

    [OPEN] [#251] Dynamically created Checkbox not Checked

    If a Checkbox is dynamically created and added to a CheckboxGroup, the Checked property does not appear to be rendering correctly.

    In the following sample, the second and third Checkbox should be checked after clicking the "Add Checkboxes" Button.

    <%@ Page Language="C#" %> 
    
    <script runat="server">
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            this.CheckboxGroup1.Items.Add(new Checkbox
            {
                ID = "Checkbox1",
                BoxLabel = "Checkbox 1",
            });
    
    
            this.CheckboxGroup1.Items.Add(new Checkbox
            {
                ID = "Checkbox2",
                BoxLabel = "Checkbox 2",
                Checked = true,
            });
    
    
            this.CheckboxGroup1.Items.Add(new Checkbox
            {
                ID = "Checkbox3",
                BoxLabel = "Checkbox 3",
                Checked = true,
            });
    
    
            this.CheckboxGroup1.Render();
        }
    </script>
    
    
    <!DOCTYPE html>
     
    <html>
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
    
    
        <ext:Button runat="server" Text="Add Checkboxes" OnDirectClick="Button1_Click" />
    
    
        <ext:CheckboxGroup 
            ID="CheckboxGroup1" 
            runat="server" 
            FieldLabel="Items" 
            ColumnsNumber="1"
            />
    </form>
    </body>
    </html>
    Last edited by Daniil; May 29, 2013 at 3:49 AM. Reason: [OPEN] [#251]
    Geoffrey McGill
    Founder
  2. #2
    Seems a work-around is presented in the following thread:

    http://forums.ext.net/showthread.php...operty-problem

    Setting IsDynamic="true" does appear to work nicely... although I would like to revisit this issue again in the future in an attempt to work-around limitations of LoadPostData.

    Example

    <%@ Page Language="C#" %> 
    
    <script runat="server">
        protected void Button1_Click(object sender, DirectEventArgs e)
        {
            this.CheckboxGroup1.Items.Add(new Checkbox
            {
                ID = "Checkbox1",
                BoxLabel = "Checkbox 1",
                IsDynamic = true,
            });
    
    
            this.CheckboxGroup1.Items.Add(new Checkbox
            {
                ID = "Checkbox2",
                BoxLabel = "Checkbox 2",
                Checked = true,
                IsDynamic = true,
            });
    
    
            this.CheckboxGroup1.Items.Add(new Checkbox
            {
                ID = "Checkbox3",
                BoxLabel = "Checkbox 3",
                Checked = true,
                IsDynamic = true,
            });
    
    
            this.CheckboxGroup1.Render();
        }
    </script>
    
    
    <!DOCTYPE html>
     
    <html>
    <head runat="server">
        <title>Ext.NET Example</title>
    </head>
    <body>
    <form runat="server">
        <ext:ResourceManager runat="server" />
    
    
        <ext:Button 
            runat="server" 
            Text="Add Checkboxes" 
            OnDirectClick="Button1_Click" 
            />
    
    
        <ext:CheckboxGroup 
            ID="CheckboxGroup1" 
            runat="server" 
            FieldLabel="Items" 
            ColumnsNumber="1"
            />
    </form>
    </body>
    </html>
    Geoffrey McGill
    Founder
  3. #3
    Hello Geoffrey,

    This problem is led by the fact that an unchecked Checkbox doesn't submit its value, i.e. it is absent in POST.

    Vladimir thinks about a possibility to render a hidden field for each Checkbox (and, probably, a Radio) and always submit its value via that hidden field. I.e. even an unchecked Checkbox will put "false" to POST.

    It could solve the problem and similar ones.

    What do you think about this approach?
  4. #4

Similar Threads

  1. treepanel how does checked only one checkbox
    By btbtbtbbt in forum 2.x Help
    Replies: 0
    Last Post: Sep 13, 2012, 3:08 AM
  2. [CLOSED] Another way to check checkbox is checked ot not....
    By rosua in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Jun 21, 2012, 5:39 AM
  3. [CLOSED] CheckBox.Checked is not getting set
    By speedstepmem3 in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 01, 2011, 11:27 AM
  4. Replies: 1
    Last Post: Jul 09, 2010, 11:57 AM
  5. Checked checkbox (Client)
    By Kaido in forum 1.x Help
    Replies: 0
    Last Post: Jul 13, 2009, 6:08 AM

Posting Permissions