[CLOSED] combobox value disappear after button click

  1. #1

    [CLOSED] combobox value disappear after button click

    Hi
    I have a combobox and a button ,and the button set with AutoPostback="true",after click on button combobox value disappear,please run the test case,also I found EmptyValue property not present in combobox.

    Sample Aspx
    <html>
    
    <body>
        <form id="Form1" runat="server">
           <ext:ResourceManager ID="ResourceManager1" runat="server" DisableViewState="false" />
            <ext:ComboBox runat="server" ID="cmpDepartment" Editable="true" DisplayField="DepartmentName" ValueField="DepartmentID" TypeAhead="true"
                EmptyText="All">
                <Triggers>
                    <ext:FieldTrigger Icon="Clear" HideTrigger="true">
                    </ext:FieldTrigger>
    
                </Triggers>
                <Listeners>
                    <Select Handler="this.getTrigger(0).show();" />
                    <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                    <TriggerClick Handler="if (index == 0) {
                                               this.clearValue();
                                               this.getTrigger(0).hide();
                                           }" />
                </Listeners>
                <Store>
                    <ext:Store
                        runat="server"
                        ID="DepartmentStore">
    
                        <Model>
                            <ext:Model ID="Model1" runat="server" IDProperty="DepartmentID">
                                <Fields>
                                    <ext:ModelField Name="DepartmentID" Type="Int" />
                                    <ext:ModelField Name="DepartmentName" Type="String" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
    
            </ext:ComboBox>
            <ext:DisplayField runat="server" ID="df" PaddingSpec="0 0 0 25" Html="&nbsp;"></ext:DisplayField>
            <ext:Button runat="server" ID="btn" OnClick="btn_Click" Text="Click" AutoPostBack="true"></ext:Button>
        </form>
    </body>
    </html>
    Sample Code

    public partial class delayed_event : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    LoadCombo();
                }
            }
    
            private void LoadCombo()
            {
                Department d ;
                List<Department> _d = new List<Department>();
                for (int i = 0; i <= 4; i++)
                {
                    d = new Department();
                    d.DepartmentID = i;
                    d.DepartmentName = "Department - " + i.ToString();
                    _d.Add(d);
                }
    
                DepartmentStore.DataSource = _d;
                DepartmentStore.DataBind();
            }
    
            protected void btn_Click(object sender, EventArgs e)
            {
    
            }
    
    
        }
    
        public class Department
        {
            public int DepartmentID { get; set; }
            public string DepartmentName { get; set; }
        }
    Last edited by Daniil; Feb 25, 2015 at 9:13 AM. Reason: [CLOSED]
  2. #2
    Hi @matrixwebtech,

    You should replace
    if (!IsPostBack)
    with
    if (!X.IsAjaxRequest)
    Otherwise, the ComboBox's Store is just not binding to the data on PostBack.
  3. #3
    Hi ,Daniil
    Change according your suggestion ,now its working.but there are one problem.

    1.I select a value from combobox,and the trigger button visible as expected.
    2.click on button ,trigger button disappear.
    how to fix this?
  4. #4
    I would try FireSelectOnLoad="true" for the ComboBox.
  5. #5
    thank you very much for help.there are many small small tricks in EXT.Net .please close this thread.
  6. #6
    I add after data bind in LoadCombo() function bellow code to add a All Option to the combo

    DepartmentStore.DataSource = _d;
                DepartmentStore.DataBind();
             this.cmpDepartment.SelectedItems.Clear();
                this.cmpDepartment.Items.Insert(0, new Ext.Net.ListItem { Text = "All", Value = "0" });
                this.cmpDepartment.SelectedItems.Add(new Ext.Net.ListItem { Index = 0 });
    All option added.but when I click on button selected item always lost and always All get selected.without adding All button click code works fine.
  7. #7
    any thought ?
  8. #8
    Mm, I don't quite understand the issue.

    Please provide a full test case. Then we could investigate.
  9. #9
    Please try bellow code

    <ext:ComboBox runat="server" ID="cmdtest" Editable="true" DisplayField="DepartmentName" ValueField="DepartmentID" TypeAhead="true"
                            EmptyText="All">
                            <Triggers>
                                <ext:FieldTrigger Icon="Clear" HideTrigger="true">
                                </ext:FieldTrigger>
    
                            </Triggers>
                            <Listeners>
                                <Select Handler="this.getTrigger(0).show();" />
                                <BeforeQuery Handler="this.getTrigger(0)[this.getRawValue().toString().length == 0 ? 'hide' : 'show']();" />
                                <TriggerClick Handler="if (index == 0) {
                                               this.clearValue();
                                               this.getTrigger(0).hide();
                                           }" />
                            </Listeners>
                            <Store>
                                <ext:Store
                                    runat="server"
                                    ID="stest">
    
                                    <Model>
                                        <ext:Model ID="Model1" runat="server" IDProperty="DepartmentID">
                                            <Fields>
                                                <ext:ModelField Name="DepartmentID" Type="Int" />
                                                <ext:ModelField Name="DepartmentName" Type="String" />
                                            </Fields>
                                        </ext:Model>
                                    </Model>
                                </ext:Store>
                            </Store>
    
                        </ext:ComboBox>
    <ext:Button runat="server" ID="btnShow" Text="Show" OnClick="btnShow_Click" AutoPostBack="true">
    public partial class test : System.Web.UI.Page
        {
           
            protected void Page_Load(object sender, EventArgs e)
            {
    
                if (!X.IsAjaxRequest)
                {
                    
                    LoadCombo();
    
    
                }
               
            }
    
            
    
    
            protected void btnShow_Click(object sender, EventArgs e)
            {
    
               
            }
    
            private void LoadCombo()
            {
                Department d;
                List<Department> _d = new List<Department>();
                for (int i = 0; i <= 4; i++)
                {
                    d = new Department();
                    d.DepartmentID = i;
                    d.DepartmentName = "Department - " + i.ToString();
                    _d.Add(d);
                }
                
    
                stest.DataSource = _d;
                stest.DataBind();
    			
    			this.cmdtest.SelectedItems.Clear();
                this.cmdtest.Items.Insert(0, new Ext.Net.ListItem { Text = "All", Value = "0" });
                this.cmdtest.SelectedItems.Add(new Ext.Net.ListItem { Index = 0 });
            }
        }
    
        public class Department
        {
            public int DepartmentID { get; set; }
            public string DepartmentName { get; set; }
        }
    1. Run this code and select ,combobox first item get selected automatically.
    2. select a option suppose Department - 4,click on button again All option get selected.

    but if I remove
    this.cmdtest.SelectedItems.Clear();
                this.cmdtest.Items.Insert(0, new Ext.Net.ListItem { Text = "All", Value = "0" });
                this.cmdtest.SelectedItems.Add(new Ext.Net.ListItem { Index = 0 });
    from LoadCombo() all works fine.
  10. #10
    Please try to set QueryMode="Local" for the ComboBox.

Similar Threads

  1. Replies: 0
    Last Post: Jan 11, 2014, 1:45 AM
  2. Replies: 0
    Last Post: Jun 12, 2012, 10:00 AM
  3. Replies: 3
    Last Post: Jan 09, 2012, 12:26 PM
  4. Replies: 0
    Last Post: May 20, 2009, 6:59 PM
  5. ComboBox selected index on button click event.
    By jmilton in forum 1.x Help
    Replies: 9
    Last Post: Mar 25, 2009, 7:06 PM

Posting Permissions