Reading checkbox value from tabpage

Page 1 of 2 12 LastLast
  1. #1

    Reading checkbox value from tabpage

    Hi,
    I'm having following problem for a while now and hope someone can confirm it's a bug, or that i'm the problem ;)

    When I use a checkbox on a tabpage, the value is not correctly posted back in a DirectEvent when the tabpage was not made visible/active. This is only with a checkbox, the value of a textfield is correctly available in the DirectEvent.

    I'm using version: 1.0.0 RC1

    Thanks for any help!

    Sander

    <%@ Page Language="C#" EnableViewState="true" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
     
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Tab1Checkbox.Checked = true;
                Tab2Checkbox.Checked = true;
                Tab2TextField.Text = "text...";
            }
        }
        public void ButtonClick(object sender, DirectEventArgs e)
        {
            //When tab 2 was not made visible/active, the value will be false and should be true (as initialized in the Page_load)....
            bool b2 = Tab2Checkbox.Checked;
            //The visible checkbox will return the value true, which is correct.
            bool b1 = Tab1Checkbox.Checked;
            //However, this value is the same as initialized in the Page_load....
            string s = Tab2TextField.Text;
        }
     
     
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Checkbox in hidden tab test</title>
    </head>
    <body>
        <form id="Form1" runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Button ID="SaveButton" runat="server" Text="Save" Icon="Accept">
            <DirectEvents>
                <Click OnEvent="ButtonClick" />
            </DirectEvents>
        </ext:Button>
        <ext:TabPanel runat="server">
            <Items>
                <ext:FormPanel ID="InvoiceRowsPanel" runat="server" Title="Tab 1" FormGroup="true"
                    AutoHeight="true">
                    <Content>
                        <ext:Checkbox runat="server" ID="Tab1Checkbox" FieldLabel="Check me" />
                    </Content>
                </ext:FormPanel>
                <ext:FormPanel ID="FormPanel1" runat="server" Title="Tab 2" FormGroup="true" AutoHeight="true">
                    <Items>
                        <ext:Checkbox runat="server" ID="Tab2Checkbox" FieldLabel="Check me" />
                        <ext:TextField runat="server" ID="Tab2TextField" FieldLabel="Some text" />
                    </Items>
                </ext:FormPanel>
            </Items>
        </ext:TabPanel>
        </form>
    </body>
    </html>
  2. #2
    //When tab 2 was not made visible/active, the value will be false and should be true (as initialized in the Page_load)....
    Hi,

    The second tab is not-rendered till it's not showed. So, checkbox's value is not in POST.

    Please try
    <ext:TabPanel runat="server" DeferredRender="false">
    and you will see the difference.

    //However, this value is the same as initialized in the Page_load....
    It's not in POST. But we see .Text which was applied in Page_Load...That's right, it's the result of ViewState's work.

    But I'm not sure why there is no the same result with Checkbox ... I will discuss this problem with Dev team.

    Maybe .Checked is not under ViewState control.
    Last edited by Daniil; Dec 07, 2010 at 11:07 AM.
  3. #3
    The problem is the following.

    When Checkbox is not in POST there may be two scenario:
    1. There is no submit.
    2. Checkbox is unchecked.

    And no way to identify what exactly scenario occurs.

    So, Dev Team decided to set .Checked to false when Checkbox is not in POST.
    Last edited by Daniil; May 24, 2012 at 8:19 AM.
  4. #4
    So, it's not a bug therefore I'm moving this thread to the Help forum.
  5. #5
    The DeferredRender="false" did the trick....

    Thanks Daniil!
  6. #6

    Solution?

    Why this behaviour only counts for checkbox's and not for other controls in the tab page?
    I'm having the same problem, the value of my checkbox always returns to false.
    But i would like to keep the deferredrender to true, otherwise my page loads too slow.

    Regards
  7. #7
    Quote Originally Posted by Birgit View Post
    Why this behaviour only counts for checkbox's and not for other controls in the tab page?
    I'm having the same problem, the value of my checkbox always returns to false.
    Well, we set false (LoadPostData) if a checkbox is not in POST. But we do nothing with textfield and, probably, ViewState handles this situation.
  8. #8
    Ok, but is there any solution to this point?
    Because i really want the deferredrender to be true, otherwist my page loads 3 times as slow... Now my page already took me 5 till 6 seconds to load, which is not acceptable by my client.
    And the only problem now is with the checkboxes, not with textfields, datefields, fileuploadfields, ...

    Regards and thanx !
    Last edited by Birgit; May 16, 2011 at 12:17 PM.
  9. #9
    Well, the one way I see - avoiding such scenario.

    If it's not possible to reconfigure the page to avoid this scenario, I can suggest the following two workarounds.

    Example 1
    <%@ Page Language="C#" EnableViewState="true" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
        private static bool Tab2Checkbox_initial_value;
          
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Tab1Checkbox.Checked = true;
                Tab2Checkbox.Checked = Tab2Checkbox_initial_value = true;
                Tab2TextField.Text = "text...";
            }
        }
        public void ButtonClick(object sender, DirectEventArgs e)
        {
            bool b2;
            if (Hidden1.Value == null)
            {
                b2 = Tab2Checkbox_initial_value;
            }
            else
            {
                b2 = Tab2Checkbox.Checked;
            }
            X.Msg.Alert("DirectEvent", "Tab2's TextField: " + Tab2TextField.Text + "<br/>" + "Tab2's Checkbox: " + b2).Show();
        }
      
      
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net.Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Save" Icon="Accept">
            <DirectEvents>
                <Click OnEvent="ButtonClick" />
            </DirectEvents>
        </ext:Button>
        <ext:TabPanel runat="server">
            <Items>
                <ext:FormPanel runat="server" Title="Tab 1">
                    <Items>
                        <ext:Checkbox ID="Tab1Checkbox" runat="server" FieldLabel="Check me" />
                    </Items>
                </ext:FormPanel>
                <ext:FormPanel runat="server" Title="Tab 2">
                    <Items>
                        <ext:Hidden ID="Hidden1" runat="server" />
                        <ext:Checkbox ID="Tab2Checkbox" runat="server" FieldLabel="Check me">
                            <Listeners>
                                <AfterRender Handler="Hidden1.setValue('rendered')" />
                            </Listeners>
                        </ext:Checkbox>
                        <ext:TextField ID="Tab2TextField" runat="server" FieldLabel="Some text" />
                    </Items>
                </ext:FormPanel>
            </Items>
        </ext:TabPanel>
        </form>
    </body>
    </html>
    Example 2
    <%@ Page Language="C#" EnableViewState="true" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
          
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Tab1Checkbox.Checked = true;
                {
                    Tab2Checkbox.Checked = true;
                    Hidden1.Value = true;
                }
                Tab2TextField.Text = "text...";
            }
        }
        public void ButtonClick(object sender, DirectEventArgs e)
        {
            bool b2 = JSON.Deserialize<bool>(Hidden1.Value.ToString().ToLower());
            X.Msg.Alert("DirectEvent", "Tab2's TextField: " + Tab2TextField.Text + "<br/>" + "Tab2's Checkbox: " + b2).Show();
        }
      
      
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net.Example</title>
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager runat="server" />
        <ext:Button runat="server" Text="Save" Icon="Accept">
            <DirectEvents>
                <Click OnEvent="ButtonClick" />
            </DirectEvents>
        </ext:Button>
        <ext:TabPanel runat="server">
            <Items>
                <ext:FormPanel runat="server" Title="Tab 1">
                    <Items>
                        <ext:Checkbox ID="Tab1Checkbox" runat="server" FieldLabel="Check me" />
                    </Items>
                </ext:FormPanel>
                <ext:FormPanel runat="server" Title="Tab 2">
                    <Items>
                        <ext:Hidden ID="Hidden1" runat="server" />
                        <ext:Checkbox ID="Tab2Checkbox" runat="server" FieldLabel="Check me" SubmitValue="false">
                            <Listeners>
                                <Check Handler="Hidden1.setValue(checked)" />
                            </Listeners>
                        </ext:Checkbox>
                        <ext:TextField ID="Tab2TextField" runat="server" FieldLabel="Some text" />
                    </Items>
                </ext:FormPanel>
            </Items>
        </ext:TabPanel>
        </form>
    </body>
    </html>
  10. #10
    Hi Daniil,

    Thanx a lot for your reply, i'm gonna check this out today, but i think it will fullfill my needs :).

    Thanx!
Page 1 of 2 12 LastLast

Similar Threads

  1. [CLOSED] TabPage with url
    By gidi in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 21, 2012, 2:49 PM
  2. Checkbox value in hidden tabpage
    By prost in forum 1.x Help
    Replies: 1
    Last Post: Nov 14, 2010, 12:48 PM
  3. Help reading back data on a page
    By as2007 in forum 1.x Help
    Replies: 1
    Last Post: Feb 28, 2010, 4:50 AM
  4. Single TabPage problem
    By rebulanyum in forum 1.x Help
    Replies: 2
    Last Post: Feb 22, 2010, 12:52 PM
  5. [CLOSED] Changeing id on tabpage
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Apr 30, 2009, 4:49 AM

Tags for this Thread

Posting Permissions