[CLOSED] ComboBox clearValue changing value on postback

  1. #1

    [CLOSED] ComboBox clearValue changing value on postback

    Hi,

    First of all, this doesn't occur on DirectEvents.

    On a ComboBox .Value property is changing from null to string.empty after a postback.

    Steps to reproduce:

    a. Checking that it is actually returning null
    1. Press button 'Combobox current value';
    2. Alert will display 'true' stating combobox's current value is null.
    3. Press 'X' to clear current value;
    4. Alert will still display 'true'.

    b. Changing default value to string.empty
    1. Select any value in the combobox;
    2. Press button 'Combobox current value';
    3. Press 'X' to clear the current value;
    4. Press button 'Combobox current value';
    5. Alert will display 'false'. The value just changed from null to string.empty.

    Bellow is the source code.

    Thanks

    <%@ Page Language="C#" %>
    
    <%@ Import Namespace="System.Collections.Generic" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">    
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!X.IsAjaxRequest)
            {
                List<object> list = new List<object>
                {
                    new {Text = "Text3", Value = 3},
                    new {Text = "Text4", Value = 4},
                    new {Text = "Text5", Value = 5}
                };
    
                this.Store1.DataSource = list;
                this.Store1.DataBind();
    
                //Please note that inner items will be above store's items
                this.ComboBox1.Items.Insert(0, new Ext.Net.ListItem("None", "-"));
            }
        }
    
        protected void InsertRecord(object sender, DirectEventArgs e)
        {
            Dictionary<string, object> values = new Dictionary<string, object>(2);
            values.Add("Text", "Text0");
            values.Add("Value", "0");
    
            this.ComboBox1.InsertRecord(1, values);
            this.ComboBox1.SelectedItem.Value = "0";
        }
    
        protected void ButtonClick(object sender, EventArgs e)
        {
            var isNull = ComboBox1.SelectedItem.Value == null;
            X.Msg.Alert("Current Value", isNull.ToString()).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>Items Actions - Ext.NET Examples</title>
        <link href="../../../../resources/css/examples.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form runat="server">
        <ext:ResourceManager ID="ResourceManager1" runat="server" />
        <ext:Store runat="server" ID="Store1">
            <Reader>
                <ext:JsonReader IDProperty="Value">
                    <Fields>
                        <ext:RecordField Name="Text" />
                        <ext:RecordField Name="Value" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>
        <p>
            1. Combo with a store and inner items (merge mode)</p>
        <br />
        <ext:ComboBox ID="ComboBox1" runat="server" StoreID="Store1" DisplayField="Text"
            ValueField="Value">
            <Items>
                <ext:ListItem Text="Text2" Value="2" />
            </Items>
            <Triggers>
                <ext:FieldTrigger Icon="Clear" Qtip="Remove selected" />
            </Triggers>
            <Listeners>
                <TriggerClick Handler="this.clearValue();" />
            </Listeners>
        </ext:ComboBox>
        <ext:Button Text="ComboBox current value" runat="server" OnClick="ButtonClick" AutoPostBack="true" />
        <br />
        </form>
    </body>
    </html>
    Last edited by Daniil; Nov 21, 2011 at 12:07 PM. Reason: [CLOSED]
  2. #2
    Hi,

    The ComboBox's SelectedItem is a ViewState member.

    But the clearValue method does nothing with ViewState.

    So, the Value and Text come from ViewState and we reset it to empty strings.

    We will consider a possibility to reset it to null to get more consistent result.

    It works during DirectEvent, because ViewState is switched off by default for DIrectEvent.
  3. #3
    The bug ticket has been created.
    https://extnet.lighthouseapp.com/pro...gs/tickets/227

    The default value for SelectedItem.Value in LoadPostData has been changed to null, revision #3783.

    There are two fixed in that revision.

    Working on the issue that you described I've discovered one minor bug more - the clearValue method didn't clear a selectedIndexField.

    It's a HiddenField with an index of a selected item.

    The bug ticket:
    https://extnet.lighthouseapp.com/pro...gs/tickets/228

    The fixes will be also publicly available with the upcoming 1.3 release.

    Thanks for the bug report!
  4. #4
    Thanks!!

    Please, mark as closed

Similar Threads

  1. [CLOSED] Refresh ComboBox after changing Store
    By ljcorreia in forum 1.x Legacy Premium Help
    Replies: 6
    Last Post: Sep 27, 2013, 3:42 PM
  2. [CLOSED] ClearValue on server
    By jeybonnet in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 08, 2011, 2:06 PM
  3. [CLOSED] combobox clearValue() in server side
    By majestic in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Oct 06, 2009, 12:10 PM
  4. ComboBox clearValue bug
    By gercas in forum Bugs
    Replies: 0
    Last Post: Jun 30, 2009, 8:20 AM
  5. [CLOSED] Changing color of a combobox label
    By Sharon in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Feb 18, 2009, 9:34 AM

Posting Permissions