[CLOSED] Ext:Hidden value

  1. #1

    [CLOSED] Ext:Hidden value

    What basic issue am I missing/overlooking in the example below? Perform the following:

    1. Launch page and inspect App.SampleHidden.value (Undefined - GOOD)
    2. Press the "DOIT" button and inspect App.SampleHidden.value ("true" - BAD, I was expecting a boolean and not a string;
    3. Press the browsers refresh button and inspect App.SampleHidden.value (true - GOOD)


    When the hidden value is set I was hoping it would always be a Boolean.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (X.IsAjaxRequest) return;
            SetHidden();
        }
    
        protected void Doit(object sender, DirectEventArgs e)
        {
            Session["ABC"] = "Set";
            SetHidden();
        }
    
        private void SetHidden()
        {
            if (Session["ABC"] == null) return;  
            SampleHidden.SetValue(Convert.ToBoolean("true"));
        }
    </script>
    
    <head runat="server">
        <title></title>
        <style type="text/css">
        </style>
        <script type="text/javascript">
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Panel runat="server">
                <Bin>
                    <ext:Hidden ID="SampleHidden" runat="server" ClientIDMode="Static" />
                </Bin>
                <Items>
                    <ext:Button runat="server" Text="DOIT" OnDirectClick="Doit" />
                </Items>
            </ext:Panel>
        </form>
    </body>
    </html>
    Last edited by Daniil; Nov 05, 2014 at 6:32 PM. Reason: [CLOSED]
  2. #2
    Hi Chris,

    Interesting.

    I can suggest this solution.
    Ext.define("MyOverrides", {
        override: "Ext.form.field.Hidden",
    
        valueToRaw: function(value) {
            return Ext.value(value, '');
            //return '' + Ext.value(value, ''); // The original function's body
        }
    });
  3. #3
    That didn't fix it. It seems that a call through a direct event is causing it to be a string again, vs the refresh browser (ie. Page_Load) is allowing it to be a Boolean.

    1. Press the browsers refresh button and inspect App.SampleHidden.value (true - GOOD)
    2. Now press the DOIT button again and we are back to a string value instead of a boolean value.
  4. #4
    The override helps me - I see a boolean true value after click on "DOIT".

    Please provide a test case with override applied.
  5. #5
    Here is the integrated code.

    I have tested this in IE9, IE8 and Chrome 31 using Ext.NET Rev 5720.

    Whenever I hit the DOIT button and inspect App.SampleHidden.value I get the string value "true", while after I press the browsers refresh button and inspect App.SampleHidden.value I get the Boolean value true.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html>
    <html>
    <script runat="server">
    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (X.IsAjaxRequest) return;
            SetHidden();
        }
    
        protected void Doit(object sender, DirectEventArgs e)
        {
            Session["ABC"] = "Set";
            SetHidden();
        }
    
        private void SetHidden()
        {
            if (Session["ABC"] == null) return;
            SampleHidden.SetValue(Convert.ToBoolean("true"));
        }
    </script>
    
    <head runat="server">
        <title></title>
        <style type="text/css">
        </style>
        <script type="text/javascript">
            Ext.form.field.Hidden.override({
    
                valueToRaw: function (value) {
                    return Ext.value(value, '');
                    //return '' + Ext.value(value, '');  // The original function's body
                }
    
            });
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:Panel runat="server">
                <Bin>
                </Bin>
                <Items>
                    <ext:Hidden ID="SampleHidden" runat="server" ClientIDMode="Static" />
                    <ext:Button runat="server" Text="DOIT" OnDirectClick="Doit" />
                </Items>
            </ext:Panel>
        </form>
    </body>
    </html>
  6. #6
    Ok. This is working just fine in my actual project, not sure why it isn't working with the code shown above.

    Was the original function's body changed to --> return '' + Ext.value(value, ''); from something else?

    Is this an actual bug and potentially fixed in the future or do I need to always have this override.
  7. #7
    I don't know how I tested:) Sorry.

    Well, I tried to suggest you a workaround (unsuccessfully), but the problem is a bit more complicated.

    It turns out that a Hidden is not supposed to deal with non-strings at all.

    Yes, hidden.value show a boolean true after page refresh, but you should use .getValue() method. It returns a string still.

    So, please deal with a string or use a Hidden's Tag.
    SampleHidden.Tag = Convert.ToBoolean("true");
    The Tag property is not converted to string, the type should persist.
  8. #8
    Got it. If have changed my code to use .tag on the clientside so the javascript looks cleaner.

    Please close the thread.

Similar Threads

  1. Render Hidden to html Input type="hidden"
    By lasalle in forum 1.x Help
    Replies: 2
    Last Post: Jun 25, 2013, 7:24 AM
  2. x-hidden Help
    By Richardt in forum 1.x Help
    Replies: 2
    Last Post: May 19, 2011, 6:13 AM
  3. Set and get Hidden value.
    By jeeshenlee in forum 1.x Help
    Replies: 2
    Last Post: May 26, 2010, 2:42 AM
  4. [1.0] Gridview hidden
    By SouthDeveloper in forum Bugs
    Replies: 3
    Last Post: Mar 30, 2010, 10:44 AM
  5. Get Hidden Value
    By EzaBlade in forum 1.x Help
    Replies: 1
    Last Post: Apr 27, 2009, 9:36 AM

Posting Permissions