Nov 01, 2010, 7:04 AM
[CLOSED] [1.0] Clean Resource Url makes a lot of difference to Direct calls javascript
CleanResourceUrl option in web.config makes a lot of difference to generated code for Direct calls (and I am sure, at other places too, I recall my colleague mentioning earlier, that he gets a "Ext is undefined" error with CleanResourceUrl enabled, but I never had a chance to look at it).
Please see the code below:
Everything goes fine, and you get an alert message.
Now disable cleanresourceurl in web.config, refresh the page, invoke the DirectMethod, and again click the new button "Click me too". This time you get a javascript error.
On analysis, I found the following to be an issue with clean urls disabled:
1) You have a control on page that requires non-standard resources (apart from the core ExtJs and Ext.Net resources), like Multiselect.
2) There's an instance of Multiselect on the page in the initial GET request.
3) Its resources are loaded onto page.
4) You override (Ext.override) or add methods to this control's prototype (e.g. a custom method is added to Ext.ux.Multiselect above).
5) You make a Direct call. More controls are rendered including the one which requires non-standard resources.
6) With CleanUrls enabled, the toolkit detects that the control resources are already on the page and does not register them again.
7) However, with clean urls disabled, the toolkit fails to detect the same, and again registers the resource on the page
Ext.net.ResourceMgr.load([{url:\"/travcom/WebResource.axd?d=V0eKQdBaIZT2bgNG12vsoa1il5G7nZbZ c_HJ3HqIXtWlHTFEUvLLop_JMMdknF0IaoPdWCdvvDpKIP1eKY YYzg2&t=634143215072483426\"})
This leads to overwriting of the previous prototype of the control, and any custom methods you added/modified to the prototype are lost.
The existing controls rendered in GET request continue to work fine with the custom methods, but controls rendered in Direct call do not have the custom methods for them, as they have not been added to their prototype.
This is almost a show-stopper, and I am working for alternatives, but if Ext.Net team can provide a solution quickly, that would be too great (I cannot enable Clean urls because we are in production for a very large deployment, and more issues have been reported with clean urls enabled).[/LIST]
Please see the code below:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load (object sender, EventArgs e)
{
if (!Ext.Net.X.IsAjaxRequest)
{
List<object>l=new List<object>();
l.Add(new { id = 1, name = "Person1" });
l.Add(new { id = 2, name = "Person2" });
l.Add(new { id = 3, name = "Person3" });
l.Add(new { id = 4, name = "Person4" });
this.store.DataSource = l;
this.store.DataBind();
}
}
[Ext.Net.DirectMethod]
public void directMethod ()
{
Ext.Net.Panel p=new Ext.Net.Panel();
Ext.Net.MultiSelect ms=new MultiSelect();
ms.ID="m2";
ms.StoreID = "store";
ms.DisplayField = "name";
ms.ValueField = "id";
ms.Width = new Unit(200, UnitType.Pixel);
ms.Height = new Unit(200, UnitType.Pixel);
p.ContentControls.Add(ms);
Ext.Net.Button b=new Ext.Net.Button();
b.Text = "Click me too!";
b.OnClientClick = "#{m2}.myCustomMethod();";
p.ContentControls.Add(b);
p.Render(this.Form);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
Ext.ux.Multiselect.prototype.myCustomMethod = function() {
alert('Test');
}
</script>
<div>
<ext:ResourceManager runat="server" />
<ext:Store runat="server" ID="store">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="id" />
<ext:RecordField Name="name" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
<ext:MultiSelect runat="server" ID="m1" Width="200" Height="300" StoreID="store" DisplayField="name" ValueField="id" />
<ext:Button runat="server" Text="Click Me" OnClientClick="#{m1}.myCustomMethod();" /></ext:Button>
<ext:Button runat="server" Text="Make Direct call" OnClientClick="Ext.net.DirectMethods.directMethod();" /></ext:Button>
</div>
</form>
</body>
</html>
Try running it with CleanReosureUrl enabled, invoke the DirectMethod, and click the new button "Click me too".Everything goes fine, and you get an alert message.
Now disable cleanresourceurl in web.config, refresh the page, invoke the DirectMethod, and again click the new button "Click me too". This time you get a javascript error.
On analysis, I found the following to be an issue with clean urls disabled:
1) You have a control on page that requires non-standard resources (apart from the core ExtJs and Ext.Net resources), like Multiselect.
2) There's an instance of Multiselect on the page in the initial GET request.
3) Its resources are loaded onto page.
4) You override (Ext.override) or add methods to this control's prototype (e.g. a custom method is added to Ext.ux.Multiselect above).
5) You make a Direct call. More controls are rendered including the one which requires non-standard resources.
6) With CleanUrls enabled, the toolkit detects that the control resources are already on the page and does not register them again.
7) However, with clean urls disabled, the toolkit fails to detect the same, and again registers the resource on the page
Ext.net.ResourceMgr.load([{url:\"/travcom/WebResource.axd?d=V0eKQdBaIZT2bgNG12vsoa1il5G7nZbZ c_HJ3HqIXtWlHTFEUvLLop_JMMdknF0IaoPdWCdvvDpKIP1eKY YYzg2&t=634143215072483426\"})
This leads to overwriting of the previous prototype of the control, and any custom methods you added/modified to the prototype are lost.
The existing controls rendered in GET request continue to work fine with the custom methods, but controls rendered in Direct call do not have the custom methods for them, as they have not been added to their prototype.
This is almost a show-stopper, and I am working for alternatives, but if Ext.Net team can provide a solution quickly, that would be too great (I cannot enable Clean urls because we are in production for a very large deployment, and more issues have been reported with clean urls enabled).[/LIST]