Cannot get SelectBox value

  1. #1

    Cannot get SelectBox value

    Please check the following example :

    <%@ Page Language="C#" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <script runat ="server">
            [DirectMethod]
            public void SelectChange()
            {
                X.MessageBox.Alert("",TestCombo.Value).Show();
            }
        </script>
    
        <form id="form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Default" />
            <ext:Panel ID="Panel1" runat="server">
                <Items>
                    <ext:SelectBox runat ="server" ForceSelection="True" Editable="False" ID="TestCombo">
                      <Items>
                        <ext:ListItem Text="Item 1" Value="1"/>
                        <ext:ListItem Text="Item 2" Value="2"/>
                        <ext:ListItem Text="Item 3" Value="3"/>
                        <ext:ListItem Text="Item 4" Value="4"/>
                      </Items>
                      <Listeners>
                        <Change Handler = "App.direct.SelectChange();" />
                      </Listeners>
                    </ext:SelectBox>
                </Items>
            </ext:Panel>
        </form>
    </body>
    </html>
    The change procedure always emits item text, not value. How can I obtain the value field?
  2. #2
    1. Set Delay to Change listener
    <Change Handler = "App.direct.SelectChange();" Delay="20" />
    2. Use SelectedItem property of SelectBox
    X.MessageBox.Alert("", TestCombo.SelectedItem != null ? TestCombo.SelectedItem.Value : "").Show();
    In your case, it is better to use button's Click DirectEvent
    Vladimir Shcheglov
    Sr. Developer
  3. #3
    Thanks, but still no go. Converted to DirectEvent, now I'm getting 500 error. Also I could not find where to put the delay :

    <%@ Page Language="C#" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <script runat ="server">
        protected void SelectChange(object sender, DirectEventArgs e)
        {
            X.Msg.Alert("",TestCombo.SelectedItem != null ? TestCombo.SelectedItem.Value : "").Show();
        }
    </script>
    
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
    
        <form id="form1" runat="server">
            <ext:ResourceManager ID="ResourceManager1" runat="server" Theme="Default" />
            <ext:Panel ID="Panel1" runat="server">
                <Items>
                    <ext:ComboBox runat ="server" ForceSelection="True" Editable="False" ID="TestCombo" OnDirectChange="SelectChange">
                      <Items>
                        <ext:ListItem Text="Item 1" Value="1"/>
                        <ext:ListItem Text="Item 2" Value="2"/>
                        <ext:ListItem Text="Item 3" Value="3"/>
                        <ext:ListItem Text="Item 4" Value="4"/>
                      </Items>
                    </ext:ComboBox>
                </Items>
            </ext:Panel>
        </form>
    </body>
    </html>
    Last edited by Irmak; Jun 07, 2012 at 5:18 PM.
  4. #4
    Your last sample works correctly, delay is not required for DirectEvent
    Vladimir Shcheglov
    Sr. Developer
  5. #5
    Thank you very much, apparently my setup was screwed up, opened a new project and added Beta 3, now everything works swell.

Similar Threads

  1. Value && Text in SelectBox in CodeBehind
    By threewonders in forum 1.x Help
    Replies: 2
    Last Post: Mar 23, 2012, 9:51 AM
  2. What's wrong in my validation of SelectBox
    By Dorababu in forum 2.x Help
    Replies: 6
    Last Post: Mar 12, 2012, 3:51 PM
  3. [CLOSED] Problem with selectbox under IE
    By Pablo_Azevedo in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Dec 30, 2011, 10:06 AM
  4. Replies: 4
    Last Post: Oct 24, 2011, 3:34 AM
  5. Problem with SelectBox example...
    By Tanielian in forum 1.x Help
    Replies: 12
    Last Post: Apr 27, 2011, 12:50 PM

Posting Permissions