PDA

View Full Version : [CLOSED] Mapping custom properties from EXT ASP.NET controls to ExtJS controls is not working



Svr77
Dec 30, 2014, 4:17 PM
Hi All,

I am using Ext.NET 2.5.3 release and found that such construction doesn't work anymore:


<ext:Button runat="server" Text="Filter" Icon="Magnifier" Id="statusFilter" MyCustomProp="1" />

in js-code, I could use it after all as


if (Ext.getCmp('statusFilter').myCustomProp == "1") {
.....
}

Now I see that all my properties defined like this are ignored and corresponding properties for ExtJS are not creating. Is this a bug or behaviour was changed since 2.5.1?

Alexander

Dimitris
Dec 30, 2014, 5:41 PM
Can you please double check? The following is working in 2.5.3:



<%@ Page Language="C#" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:Button runat="server" Text="Filter" Icon="Magnifier" Id="statusFilter" MyCustomProp="111">
<Listeners>
<Click Handler="alert(Ext.getCmp('statusFilter').myCustomProp);" />
</Listeners>
</ext:Button>

</form>
</body>
</html>

Svr77
Dec 30, 2014, 7:10 PM
Hi Mimisss,

Yes, I've checked and found that it works in your case. However if you try to do it using ToConfig this doesn't work. For instance, like this:


string str = ComponentLoader.ToConfig("<ext:Button runat=\"server\" Text=\"Filter\" Icon=\"Magnifier\" Id=\"statusFilter\" MyCustomProp=\"1\" />")

Honestly, now I am not sure, did it work before like this in my application because I did a lot of changes :-)

Alexander

Daniil
Dec 31, 2014, 1:57 PM
Hi Alexander,

If you define some custom property in markup, it is a shorthand for a control's CustomConfig. In code behind you cannot just define a non-existing property, so, you have to use a CustomConfig.

A .ToConfig() call appears to be working correctly with a CustomConfig.

Example

<%@ Page Language="C#" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
var btn = new Ext.Net.Button();
btn.CustomConfig.Add(new ConfigItem("customProp", "customPropValue"));
X.Msg.Alert(".ToConfig()", ComponentLoader.ToConfig(btn)).Show();
}
}
</script>

<!DOCTYPE html>

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
</form>
</body>
</html>

Svr77
Jan 04, 2015, 11:34 AM
Hi Daniil,

You example works but I have a bit different aspect. First of all, I think it is only related with GridPanel, because with other controls seems it is working fine. Here is detailed steps how to reproduce it:

1) Create a simple control and place GridPanel inside of it. Also define custom properties directly in ASPX code:


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" ClientIDMode="Static" %>

<ext:GridPanel Frame="true" Layout="Fit" runat="server" MyCustomProp="1">
<Buttons>
<ext:Button runat="server" Text="Ok" MyCustomProp="2" />
<ext:Button runat="server" Text="Cancel" MyCustomProp="3" />
</Buttons>
</ext:GridPanel>


2) Write a simple controller that will load this control and generate control's config like this:


public string TestController()
{
ViewUserControl uc1 = (ViewUserControl)UserControlRenderer.LoadControl("~/Views/Shared/test.ascx");
string str = ComponentLoader.ToConfig(uc1);
return str;
}


3) The controller will return you the following string:

[{"frame":true,"xtype":"grid","layout":"fit","buttons":[{"text":"Ok"},{"text":"Cancel"}],"columns":{}}]

As you see in the results you can't find any mention about MyCustomProp. However for the following control:



<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" ClientIDMode="Static" %>

<ext:Panel Frame="true" Layout="Fit" runat="server" MyCustomProp="1">
<Buttons>
<ext:Button runat="server" Text="Ok" MyCustomProp="2" />
<ext:Button runat="server" Text="Cancel" MyCustomProp="3" />
</Buttons>
</ext:Panel>


the results will be completely different:


[{myCustomProp:1,frame:true,xtype:"panel",layout:"fit",buttons:[{myCustomProp:2,text:"Ok"},{myCustomProp:3,text:"Cancel"}]}]

Can you explain why this is not working in case of GridPanel?

Thanks,
Alexander

Daniil
Jan 05, 2015, 1:58 PM
That is a defect. Thank you for the report!

Created an Issue.
https://github.com/extnet/Ext.NET/issues/628

It has been fixed:

v2: revision 6240 (branches/2). It goes to v2.5.4.


v3: revision 6241 (trunk). It goes to v3.1.