Originally Posted by
Daniil
Do you mean a "store.load()" call under "your solution"? If yes, then it is executed once in the place where you put it. It is not like an event listener.
Sorry, I didn't understand why you can use this approach. Please elaborate.
Well, hard to say anything concrete without a test case. I guess the breakpoint allows the Store to finish its load request. The ComboBox sets its value.
So, where do you put a breakpoint? And how do you apply a value to ComboBox?
here is sample for recreate:
handler.ashx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Ext.Net;
namespace Ext.NetTest2.x
{
/// <summary>
/// Summary description for HandlerProxy
/// </summary>
[Serializable]
public class MyClass
{
public int Id { get; set; }
public string Name { get; set; }
public MyClass(int id, string name)
{
Id = id;
Name = name;
}
}
public class HandlerProxy : IHttpHandler
{
private List<MyClass> myClasses = new List<MyClass>()
{
new MyClass(1,"first"),
new MyClass(2,"second"),
new MyClass(3,"third")
};
public void ProcessRequest(HttpContext context)
{
string sessionName = string.Empty;
string query = string.Empty;
if (!string.IsNullOrEmpty(context.Request["session_name"]))
sessionName = context.Request["session_name"];
if (!string.IsNullOrEmpty(context.Request["query"]))
query = context.Request["query"];
if (!string.IsNullOrEmpty(query))
{
List<MyClass> queryResult = myClasses.Where(x => x.Name.ToLower().Contains(query.ToLower())).ToList();
context.Response.Write(JSON.Serialize(queryResult));
}
else
{
context.Response.Write(JSON.Serialize(myClasses));
}
}
public bool IsReusable
{
get
{
return false;
}
}
}
}
aspx
<%@ Page Language="C#" %>
<%@ Register tagPrefix="ext" assembly="Ext.Net" namespace="Ext.Net" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public class ComboboxLoadOnExpand : Ext.Net.ComboBox
{
private Ext.Net.Store store;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
store = new Ext.Net.Store();
Ext.Net.JsonReader reader = new JsonReader();
Ext.Net.Model model = new Ext.Net.Model {ID = this.ID + "_model"};
model.Fields.AddRange(new List<ModelField> {new ModelField("Id", ModelFieldType.Int), new ModelField("Name", ModelFieldType.String)});
reader.IDProperty = "Id";
reader.MessageProperty = "Name";
reader.Root = "data";
reader.TotalProperty = "total";
Ext.Net.AjaxProxy proxy = new Ext.Net.AjaxProxy();
proxy.Url = "~/HandlerProxy.ashx";
proxy.ActionMethods.Read = HttpMethod.POST;
proxy.Timeout = 30000;
proxy.Reader.Add(reader);
store.ID = this.ID + "_Store";
store.AutoLoad = false;
store.WarningOnDirty = false;
store.Model.Add(model);
store.Proxy.Add(proxy);
this.Store.Add(store);
store.Parameters.Add(new StoreParameter("session_name", "session"));
//store.BaseParams["session_name_param1"] = JSON.Serialize(new List<Parameter>{new Parameter(0,"param1"),new Parameter(2,"param2")});
this.DisplayField = "Name";
this.ValueField = "Id";
this.Editable = true;
this.TypeAhead = false;
this.MinChars = 1;
this.TriggerAction = TriggerAction.All;
}
}
private ComboboxLoadOnExpand combo;
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
combo = new ComboboxLoadOnExpand{ID="combo",Height=26};
comboContainer.Items.Add(combo);
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (!X.IsAjaxRequest)
{
combo.GetStore().DataSource = new object[] {new {Id = 2, Name = "second"}};
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<ext:ResourceManager runat="server"></ext:ResourceManager>
<ext:Viewport runat="server" ID="viewport">
<LayoutConfig>
<ext:VBoxLayoutConfig runat="server" Align="Stretch"/>
</LayoutConfig>
<Items>
<ext:Toolbar runat="server" ID="toolbar" Height="40">
<LayoutConfig>
<ext:HBoxLayoutConfig runat="server" Align="Stretch"/>
</LayoutConfig>
<Items>
<ext:Button runat="server" ID="btnSample" Text="This is only for simulate layout"></ext:Button>
</Items>
</ext:Toolbar>
<ext:Container runat="server" ID="container" Flex="1" Layout="FitLayout">
<Items>
<ext:Container runat="server" ID="comboContainer">
</ext:Container>
</Items>
</ext:Container>
</Items>
</ext:Viewport>
</body>
</html>
web.config httpHandlers section
<httpHandlers>
<add verb="*" path="~/HandlerProxy.ashx" validate="false" type="Ext.NetTest2.x.HandlerProxy, Ext.NetTest2.x" />
<add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
</httpHandlers>
It's reproduce problem with remote loading default value. It's
important to use handler here.
addding
ListItem with Index = 0 to SelectedItems collection doesn't change anything as well.