Apr 20, 2013, 8:27 AM
[FIXED] [2.3] Some trouble with ComboBox
Hello,everyone.
I have a Page which a FormPanel(there's a ComboBox in it) and a TreePanel(has a default root node) in it and open ViewState.
I set a value to ComboBox in GET.
When i GET the page the TreePanel's Store send a POST request(store read) before FormPane rendered in client,in this POST request the fromdata has no info about FormPane.
in the POST request recover the ComboBox.Value from ViewState,but in ComboBoxBase.LoadPostData() Ext.Net get value from formdata and cover ComboBox.Value without precondition
it's ComboBoxBase.LoadPostData() code
protected override bool LoadPostData(string postDataKey, NameValueCollection postCollection)
{
this.HasLoadPostData = true;
string text = postCollection[this.UniqueName];
string state = postCollection[this.ValueHiddenName.IsNotEmpty() ? this.ValueHiddenName : ("_" + this.UniqueName + "_state")];
this.SuspendScripting();
this.RawValue = text;
this.Value = text;
this.ResumeScripting();
if (state == null && text == null)
{
return false;
}
if (!this.EmptyText.Equals(text) && text.IsNotEmpty())
{
List<ListItem> items = null;
if (this.SimpleSubmit)
{
var array = state.Split(new char[] { ',' });
items = new List<ListItem>(array.Length);
foreach (var item in array)
{
items.Add(new ListItem(item));
}
}
else if(state.IsNotEmpty())
{
items = ComboBoxBase.ParseSelectedItems(state);
}
bool fireEvent = false;
if (items == null)
{
items = new List<ListItem>
{
new ListItem(text)
};
/*fireEvent = this.SelectedItems.Count > 0;
this.SelectedItems.Clear();
return fireEvent;
*/
}
foreach (var item in items)
{
if (!this.SelectedItems.Contains(item))
{
fireEvent = true;
break;
}
}
this.SelectedItems.Clear();
this.SelectedItems.AddRange(items);
return fireEvent;
}
else
{
if (this.EmptyText.Equals(text) && this.SelectedItems.Count > 0)
{
this.SelectedItems.Clear();
return true;
}
}
return false;
}
Look at Line 5 to 11,why not change like this
string text = postCollection[this.UniqueName];
string state = postCollection[this.ValueHiddenName.IsNotEmpty() ? this.ValueHiddenName : ("_" + this.UniqueName + "_state")];
this.SuspendScripting();
this.RawValue = text;
this.ResumeScripting();
if (state == null && text == null)
{
return false;
}
this.SuspendScripting();
this.Value = text;
this.ResumeScripting();
Sample for this question
- page file
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <ext:ResourceManager ID="ResourceManager1" runat="server" DisableViewState="false" AjaxViewStateMode="Enabled" ViewStateMode="Enabled"/> <form id="form1" runat="server"> <ext:Viewport runat="server" ID="VP"> </ext:Viewport> </form> </body> </html>
- cs file
public partial class WebFormTest : System.Web.UI.Page { protected override void OnInitComplete(EventArgs e) { FP = new FormPanel(); FP.ID = "FP"; FP.Title = "FP"; FP.Region = Region.Center; TF = new TextField(); TF.ID = "TF"; TF.FieldLabel = "TF"; CB = new ComboBox(); CB.ID = "CB"; CB.FieldLabel = "CB"; CB.Items.Clear(); CB.Items.Add(new ListItem("one", "1")); CB.Items.Add(new ListItem("two", "2")); Button test = new Button() { ID = "testbtn", Text = "test" }; test.Listeners.Click.Handler = "App.Store2.load()"; FP.TopBar.Add(new Toolbar() { Items = { test } }); FP.Items.Add(TF); FP.Items.Add(CB); TP = new TreePanel(); TP.ID = "TP"; TP.Title = "TP"; TP.Region = Region.East; TP.RootVisible = false; TP.Root.Add(new Node() { NodeID = "test", Text = "test" }); Store2 = new TreeStore(); Store2.ID = "Store2"; Store2.ReadData += new TreeStoreBase.ReadDataEventHandler(Store2_ReadData); TP.Store.Add(Store2); VP.Items.Add(FP); VP.Items.Add(TP); if (!X.IsAjaxRequest) { CB.Value = "2"; TF.Value = "TEXT"; } base.OnInitComplete(e); } FormPanel FP; TextField TF; ComboBox CB; TreePanel TP; TreeStore Store2; void Store2_ReadData(object sender, NodeLoadEventArgs e) { } protected void Page_Load(object sender, EventArgs e) { } protected void WebFormTest_ReadData(object sender, StoreReadDataEventArgs e) { } }
Last edited by Daniil; May 07, 2013 at 3:30 AM.
Reason: [FIXED] [2.3]