Dec 01, 2014, 6:42 PM
[CLOSED] JsonSerializerSettings breaks TriggerField
After more than 5 hours i was able to find what was breaking TriggerField :(
When JSON.GlobalSettings is set to new Newtonsoft.Json.JsonSerializerSettings() (Global.asax line 5), the FieldTrigger does not work as expected.
Error
It was supposed to be:
Global.asax
Unfortunately in my scenario was pretty more difficult to find what was going on because i use ComponentLoader to render the page contents, so, i had to "deconstruct" my application to a smaller (smallest) scenario to be able to identify the issue
When JSON.GlobalSettings is set to new Newtonsoft.Json.JsonSerializerSettings() (Global.asax line 5), the FieldTrigger does not work as expected.
Error
It was supposed to be:
Global.asax
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
JSON.GlobalSettings = new Newtonsoft.Json.JsonSerializerSettings();
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
}
protected void Application_AuthenticateRequest(object sender, System.EventArgs e)
{
string url = HttpContext.Current.Request.FilePath;
if (url.EndsWith("ext.axd"))
{
HttpContext.Current.SkipAuthorization = true;
}
}
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{extnet-root}/{extnet-file}/ext.axd");
routes.MapRoute("Default", "{controller}/{action}");
}
}
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
</head>
<body>
<ext:ResourceManager runat="server" SeparateUIStyles="false" Theme="Gray" />
<ext:DropDownField Margin="10"
ID="_ddd"
Editable="false"
Width="800"
runat="server">
<Triggers>
<ext:FieldTrigger Icon="Clear" Weight="-1" />
</Triggers>
<Component>
<ext:Panel Title="Inner Panel" runat="server" Height="600">
<Loader Url="http://www.ext.net" Mode="Frame" runat="server" />
</ext:Panel>
</Component>
</ext:DropDownField>
</body>
</html>
Unfortunately in my scenario was pretty more difficult to find what was going on because i use ComponentLoader to render the page contents, so, i had to "deconstruct" my application to a smaller (smallest) scenario to be able to identify the issue
<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<script type="text/javascript">
var DocumentReady = function () {
ProcessContent(App._hdnContent.value, BindContent);
}
var ProcessContent = function (content) {
content = Ext.decode(content, true);
var auxContent = content;
if (auxContent && auxContent['x.res']) {
if (auxContent.config) {
content = Ext.decode(auxContent.config, true);
}
if (auxContent['x.res'].ns) {
Ext.ns.apply(Ext, auxContent['x.res'].ns);
}
if (auxContent['x.res'].res) {
Ext.net.ResourceMgr.load(auxContent['x.res'].res, function () {
BindContent(content);
});
}
else {
BindContent(content);
}
}
else {
BindContent(content);
}
}
var BindContent = function (content) {
if (content != null) {
App._vwp.add(content);
}
App._hdnContent.destroy();
}
</script>
</head>
<body>
<ext:ResourceManager runat="server" Theme="Gray">
<Listeners>
<DocumentReady Handler="DocumentReady();" Delay="1000" />
</Listeners>
</ext:ResourceManager>
<ext:Hidden ID="_hdnContent" Text="<%# ViewBag.ApplicationContent %>"
AutoDataBind="true" runat="server" />
<ext:Panel ID="_vwp" Padding="10" Width="300" Layout="FitLayout" Border="false" runat="server">
</ext:Panel>
</body>
</html>
public class ExampleController : System.Web.Mvc.Controller
{
public ActionResult Index()
{
SelectBox sb = new SelectBox
{
FieldLabel = "Ext.Net",
};
sb.Items.Add(new ListItem { Text = "E", Value = "1" });
sb.Items.Add(new ListItem { Text = "X", Value = "2" });
sb.Items.Add(new ListItem { Text = "T", Value = "3" });
sb.Triggers.Add(new FieldTrigger { Icon = TriggerIcon.Clear, Weight = -1 });
ViewBag.ApplicationContent = ComponentLoader.ToConfig(sb);
return View();
}
}
Last edited by Daniil; Dec 08, 2014 at 2:00 PM.
Reason: [CLOSED]