Nov 20, 2011, 10:22 PM
[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
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]