[CLOSED] strange ComboBox behaviour

  1. #1

    [CLOSED] strange ComboBox behaviour

    I have a ComboBox with 2 items inside (added programatically) and after submitting the form the cb.Items.Count property is always 0, even though the combobox has items inside, cb.SelectedItem is not null and cb.SelectedIndex is 0 or 1
  2. #2

    RE: [CLOSED] strange ComboBox behaviour

    Hi,

    ComboBox Items collection is not saved in ViewState. Therefore if you dynamically added items then on the next request these items will be absent in Items collection.


    It is ok if AjaxEvent. But if you make classic ASP.NET postback then you need recreate these items*
  3. #3

    RE: [CLOSED] strange ComboBox behaviour

    this is an AjaxEvent. look at the example below

    <%@ Page Language="C#"  %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-W3CDTD XHTML 1.0 TransitionalEN" "http:www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http:www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!Coolite.Ext.Web.Ext.IsAjaxRequest)
                {
                    this.cbTemplate.Items.Clear();
                    this.cbTemplate.Items.Add(new Coolite.Ext.Web.ListItem("item 1", "1"));
                    this.cbTemplate.Items.Add(new Coolite.Ext.Web.ListItem("item 2", "2"));
                    this.cbTemplate.Items.Add(new Coolite.Ext.Web.ListItem("item 3", "3"));
                    this.cbTemplate.SetValue("1");
                }
            }
    
            protected void PreviewTemplate(object sender, Coolite.Ext.Web.AjaxEventArgs e)
            {
                Ext.MessageBox.Alert("combobox items", this.cbTemplate.Items.Count.ToString()).Show();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server">
            </ext:ScriptManager>
            
            <ext:ComboBox ID="cbTemplate" runat="server" Editable="false" Width="200" ForceSelection="true" Select&#111;nfocus="true">
                <AjaxEvents>
                    <Select OnEvent="PreviewTemplate">
                    </Select>
                </AjaxEvents>
            </ext:ComboBox>
        </form>
    </body>
    </html>
    after selecting a comboBox option, the alert displays "0".

  4. #4

    RE: [CLOSED] strange ComboBox behaviour

    Hi,

    Yes, there is correct. As I said Items is not saved to the ViewState. Therefore you get empty Items collection on next request.


    When I said that *"It is ok if AjaxEvent" I mean that during AjaxEvent Combo is not rerendering therefore this empty collection is not affected on it.


    If you use these items in each request you must recreate it on each request (as dynamic controls)

Similar Threads

  1. Strange behaviour in markup
    By Paul D in forum 1.x Help
    Replies: 1
    Last Post: Nov 09, 2010, 12:27 PM
  2. Replies: 0
    Last Post: Feb 01, 2010, 5:44 AM
  3. [CLOSED] Strange behaviour of ComboBox in Grid Toolbar
    By macap in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: Sep 01, 2009, 6:45 AM
  4. Replies: 7
    Last Post: May 09, 2009, 8:06 AM
  5. Gridpanel with combobox, strange behaviour
    By Jurke in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Dec 17, 2008, 5:59 AM

Posting Permissions