[CLOSED] Set SelectedItem.Value in codebehind, get value in DocumentReady

  1. #1

    [CLOSED] Set SelectedItem.Value in codebehind, get value in DocumentReady

    Hi
    Im migrating some code från 1.x to 3.2. And I ran into some problems.
    I have a combobox that I load up in PageLoad(), and I also set the SelectedItem of it in PageLoad().
    Then I have a function running in DocumentReady, that I want to pick up the value set in PageLoad() to hide/show a button.
    This I cant get to work in ver. 3.2

    Please see test example

    <%@ Page Language="C#" %>
    
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    
    <script runat="server">
    
    
    
    
        protected void Page_Load(object sender, EventArgs e)
        {
    
    
            List<Combo> list = new List<Combo>();
    
    
            list.Add(new Combo { ID = "0", Name = "Hide" });
            list.Add(new Combo { ID = "1", Name = "Show" });
    
    
            storePrio.DataSource = list;
            storePrio.DataBind();
    
    
            cbPrio.SelectedItem.Value = "0";
        }
    
    
    
    
    </script>
    
    
    <!DOCTYPE html>
    
    
    <html>
    <head runat="server">
        <title></title>
    
    
        <script type="text/javascript">
            function PrioChange() {
                try {
                    var prioValue = App.cbPrio.getValue();
    
    
                    if (prioValue == "0") {
                        Ext.get(btnOk).hide();
                    }
                    else {
                        Ext.get(btnOk).show();
                    }
                }
                catch (e) {
                    Ext.Msg.alert('Error', e.message);
                }
            }
        </script>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server">
                <Listeners>
                    <DocumentReady Handler="PrioChange();" />
                </Listeners>
            </ext:ResourceManager>
    
    
            <ext:Store ID="storePrio" runat="server">
                <Model>
                    <ext:Model runat="server" IDProperty="ID">
                        <Fields>
                            <ext:ModelField Name="ID" />
                            <ext:ModelField Name="Name" />
                        </Fields>
                    </ext:Model>
                </Model>
    
    
            </ext:Store>
    
    
            <ext:Panel runat="server" Title="Panel">
                <Items>
                    <ext:ComboBox FieldLabel="Prio" ID="cbPrio" Width="200" runat="server" Editable="false" Mode="Local"
                        TriggerAction="All"
                        StoreID="storePrio"
                        DisplayField="Name"
                        ValueField="ID">
                        <Listeners>
                            <Select Handler="PrioChange();" />
                        </Listeners>
                    </ext:ComboBox>
    
    
                </Items>
                <Buttons>
                    <ext:Button runat="server" ID="Button1" Text="Cancel" Icon="Cancel">
                        <DirectEvents>
                        </DirectEvents>
                    </ext:Button>
    
    
                    <ext:Button runat="server" ID="btnOk" Text="Ok" Icon="Accept">
                        <DirectEvents>
                        </DirectEvents>
                    </ext:Button>
                </Buttons>
            </ext:Panel>
    
    
        </form>
    </body>
    </html>
    Best regards
    Mikael Jürke
    Last edited by fabricio.murta; Sep 12, 2016 at 11:03 PM.
  2. #2
    Hello Mikael!

    I think you can simplify your sample, removing the call from resource manager and changing the combo box listener from Select to Change.

    There's a race condition if you rely on the document being ready to assume a value from the combo box. Best is to use the value as soon as it gets assigned to the component.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    By the way, you didn't provide how you are defining the sample Combo class and I've made an assumption for its shape. This can define the reason of a problem when you report an issue, specially related to data loading. So next time, please provide the full code to reproduce the issue, including all artifacts to run it, as simple as they may seem. We are just left wondering in our side otherwise.

    Of course, if the directions above do not work, this will probably be the case (I personally doubt it at this time!), then providing the missing parts to reproduce the test case will be required in order for us to be able to give you a proper feedback!

    Hope you understand!
    Fabrício Murta
    Developer & Support Expert
  4. #4
    Hi
    Sorry about missing to provide the declaration for the Combo class, it looks like this
    public class Combo
    {
        public string ID { get; set; }
        public string Name { get; set; }
    }
    Anyway, your suggestion work just fine. Thanks.

    Best regards
    Mikael
  5. #5
    Glad it worked, and thanks for providing the definition of the Combo class, seems I reproduced it correctly. No matter what, it will be very useful here if we need to refer to this issue in the future!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 3
    Last Post: Oct 14, 2015, 2:56 PM
  2. [CLOSED] Store seems empty on DocumentReady
    By vadym.f in forum 3.x Legacy Premium Help
    Replies: 2
    Last Post: Aug 24, 2015, 6:41 PM
  3. [CLOSED] DocumentReady Fn delegate isn't called
    By vadym.f in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: May 21, 2013, 2:48 PM
  4. How to expand the DropDownField on DocumentReady?
    By phinoppix in forum 1.x Help
    Replies: 1
    Last Post: Aug 02, 2011, 3:35 PM
  5. DocumentReady Listener not firing
    By Tbaseflug in forum 1.x Help
    Replies: 1
    Last Post: Aug 28, 2009, 2:16 PM

Posting Permissions