[CLOSED] why can not pass to the code behind?

  1. #1

    [CLOSED] why can not pass to the code behind?

    in code behind , can get selected item's value through below code:
    var v =cb_sheet.SelectedItem.Value;
    but in directevent parameter ,
    <ext:ComboBox ID="cb_sheet" Margin="2" runat="server" InputWidth="120">
                                        <DirectEvents>
                                            <Change OnEvent="SheetChange">
                                                <EventMask ShowMask="True"/> 
                                                <ExtraParams>
                                                    <ext:Parameter Name="sheetid" Value="this.SelectedItem.Value" Mode="Raw"/>
                                                </ExtraParams>
                                            </Change> 
                                            
                                        </DirectEvents>
                                    </ext:ComboBox>
    Uncaught TypeError: Cannot read property 'Value' of undefined
    Last edited by Daniil; Sep 03, 2013 at 5:04 AM. Reason: [CLOSED]
  2. #2
    Hi @tobros,

    A DirectEvent's ExtraParams are populated in JavaScript. So, a Parameter's Value is supposed to be valid JavaScript if you use Mode="Raw".

    Consider
    Value="this.SelectedItem.Value"
    "this" reference is a ComboBox itself. But it doesn't have the JavaScript SelectedItem property. Therefore a JavaScript error occurs.

    This should work:
    <ext:Parameter Name="sheetid" Value="records[0].get(this.valueField)" Mode="Raw" />
  3. #3
    Quote Originally Posted by Daniil View Post
    Hi @tobros,

    A DirectEvent's ExtraParams are populated in JavaScript. So, a Parameter's Value is supposed to be valid JavaScript if you use Mode="Raw".

    Consider
    Value="this.SelectedItem.Value"
    "this" reference is a ComboBox itself. But it doesn't have the JavaScript SelectedItem property. Therefore a JavaScript error occurs.

    This should work:
    <ext:Parameter Name="sheetid" Value="records[0].get(this.valueField)" Mode="Raw" />
    why use records[0] , what is record? every control has a record?
    where can I find records[0].get method , do you have related api?
  4. #4
    unfortunately
    <ext:ComboBox ID="cb_sheet" Margin="2" runat="server" InputWidth="120">
                                        <DirectEvents>
                                            <Change OnEvent="SheetChange">
                                                <EventMask ShowMask="True"/> 
                                                <ExtraParams>
                                                    <ext:Parameter Name="sheetid" Value="records[0].get(this.valueField)" Mode="Raw"/>
                                                </ExtraParams>
                                            </Change> 
                                            
                                        </DirectEvents>
                                    </ext:ComboBox>
    "extraParams": {"sheetid":records[0].get(this.valueField)},
    Uncaught ReferenceError: records is not defined
  5. #5
    Sorry, I mixed up with the Select event.

    In the Change event please use newValue.
    http://docs.sencha.com/extjs/4.2.1/#...d-event-change

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "1", "Item 1" },
                    new object[] { "2", "Item 2" },
                    new object[] { "3", "Item 3" }
                };
            }
        }
    
        protected void ComboBox_Change(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("ComboBox_Change", e.ExtraParams["value"]).Show();
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:ComboBox 
                ID="ComboBox1" 
                runat="server" 
                DisplayField="text" 
                ValueField="value">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="value" />
                                    <ext:ModelField Name="text" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Reader>
                            <ext:ArrayReader />
                        </Reader>
                    </ext:Store>
                </Store>
                <DirectEvents>
                    <Change OnEvent="ComboBox_Change">
                        <ExtraParams>
                            <ext:Parameter Name="value" Value="newValue" Mode="Raw" />
                        </ExtraParams>
                    </Change>
                </DirectEvents>
            </ext:ComboBox>
        </form>
    </body>
    </html>
  6. #6
    Quote Originally Posted by Daniil View Post
    Sorry, I mixed up with the Select event.

    In the Change event please use newValue.
    http://docs.sencha.com/extjs/4.2.1/#...d-event-change

    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                Store store = this.ComboBox1.GetStore();
                store.DataSource = new object[] 
                { 
                    new object[] { "1", "Item 1" },
                    new object[] { "2", "Item 2" },
                    new object[] { "3", "Item 3" }
                };
            }
        }
    
        protected void ComboBox_Change(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("ComboBox_Change", e.ExtraParams["value"]).Show();
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
            <ext:ComboBox 
                ID="ComboBox1" 
                runat="server" 
                DisplayField="text" 
                ValueField="value">
                <Store>
                    <ext:Store runat="server">
                        <Model>
                            <ext:Model runat="server">
                                <Fields>
                                    <ext:ModelField Name="value" />
                                    <ext:ModelField Name="text" />
                                </Fields>
                            </ext:Model>
                        </Model>
                        <Reader>
                            <ext:ArrayReader />
                        </Reader>
                    </ext:Store>
                </Store>
                <DirectEvents>
                    <Change OnEvent="ComboBox_Change">
                        <ExtraParams>
                            <ext:Parameter Name="value" Value="newValue" Mode="Raw" />
                        </ExtraParams>
                    </Change>
                </DirectEvents>
            </ext:ComboBox>
        </form>
    </body>
    </html>
    thank you ,
    i can get parameter from directevents according extjs's event api?
    such as this:change( this, newValue, oldValue, eOpts )
    if I want to get oldValue , i can define
    <ext:Parameter Name="value" Value="oldValue" Mode="Raw" />
    another event:select( combo, records, eOpts )
    so
    <ext:Parameter Name="r" Value="records" Mode="Raw" />
    the selected records will be pass to codebehind?
  7. #7
    Quote Originally Posted by tobros View Post
    i can get parameter from directevents according extjs's event api?
    such as this:change( this, newValue, oldValue, eOpts )
    if I want to get oldValue , i can define
    <ext:Parameter Name="value" Value="oldValue" Mode="Raw" />
    Yes, you are right. The listener's arguments are accessible in the ExtraParams section of DirectEvent if you use Mode="Raw".

    However, rarely the arguments' names can be a bit different in Ext.NET rather in ExtJS.

    To check the signature in Ext.NET you can use this example.
    https://examples2.ext.net/#/Events/Listeners/Arguments/

    Quote Originally Posted by tobros View Post
    another event:select( combo, records, eOpts )
    so
    <ext:Parameter Name="r" Value="records" Mode="Raw" />
    the selected records will be pass to codebehind?
    Well, yes, you have access to the records argument. However, it cannot be used such a way, because records is an array of complex objects (records) which cannot be serialized to be sent to server. You have to extract required primitive data from records. Like I demonstrated:
    <ext:Parameter Name="sheetid" Value="records[0].get(this.valueField)" Mode="Raw" />

Similar Threads

  1. Replies: 4
    Last Post: Apr 27, 2012, 2:07 PM
  2. Replies: 2
    Last Post: Feb 01, 2012, 6:56 AM
  3. Replies: 0
    Last Post: Feb 18, 2010, 4:28 AM
  4. Pass ID from GridPanel
    By ulrikn in forum 1.x Help
    Replies: 3
    Last Post: Oct 27, 2009, 7:05 AM
  5. Replies: 0
    Last Post: May 20, 2009, 6:59 PM

Posting Permissions