PDA

View Full Version : [CLOSED] [Bug 2.3.1] HtmlBin in a UserControl Window does not render HtmlBin properly on UserControl.Update()



michaeld
Dec 01, 2013, 11:24 AM
Certain HtmlBin stream parts lose their first characters.

See this sample...


<%@ Page Language="C#" %>
<script runat="server">
protected void Page_Load( object sender, EventArgs e ) {
}
protected void OnLoad( object sender, DirectEventArgs e ) {
// Render the New Account Ask Question
AddDirectControl( Page.Form, "Test42.ascx", "uc", null );
}
/// <summary>
/// Add a User Control during a Direct Event that needs to be Rendered
/// </summary>
public delegate void BindFn( System.Web.UI.Control ctr );
public static System.Web.UI.Control AddDirectControl( HtmlForm form, string ctlPath, string ctlName, BindFn bindFn = null ) {
// Add the user control
var uc = form.Page.LoadControl( ctlPath );
uc.ClientIDMode = System.Web.UI.ClientIDMode.Static;
uc.ID = ctlName;

var Context = HttpContext.Current;

// Give a chance to bind before adding the control
if( bindFn != null )
bindFn( uc );

// Add the control
X.ControlsScripting = false;
form.Controls.Add( uc );
//X.DirectRendering = false;

// Update the Container
uc.Update();
return uc;
}
</script>

<!DOCTYPE html>
<html>
<head id="Head1" runat="server">
<title>Test42</title>
</head>
<body>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" ScriptMode="Debug" SourceFormatting="true" />


<ext:Viewport ID="vp" runat="server" Layout="VBoxLayout">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>

<ext:Panel ID="P" runat="server" Border="false" Padding="3" Flex="1" Title="Test42" Layout="VBoxLayout">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<Items>
<ext:Button ID="Test" runat="server" Text="Test" OnDirectClick="OnLoad" />
</Items>
</ext:Panel>

</Items>
</ext:Viewport>
</form>
</body>
</html>




<%@ Control Language="C#" ClassName="Test42" %>

<ext:Window ID="P" runat="server" Border="false" Padding="3" Flex="1" Title="Test42" Layout="VBoxLayout" AutoShow="true">
<LayoutConfig>
<ext:VBoxLayoutConfig Align="Stretch" />
</LayoutConfig>
<HtmlBin>
<style type="text/css">
.AddNote { display:block; margin:-2px 10px 0 40px; text-align:justify; font-style:italic; color:#555577; }
.x-form-cb-label-after { display: inline !important; } /* check after sencha bug */
</style>
<script type="text/javascript">
var NewAcct = {
select: function (sel, unsel) {
}
}
</script>
</HtmlBin>
<Items>
<ext:Label ID="Label1" runat="server" Flex="1" Html="Inner" />
</Items>
</ext:Window>

michaeld
Dec 01, 2013, 12:18 PM
Also please note that <Ext.Net.Direct.Response></Ext.Net.Direct.Response> is inserted instead of the actual control.

Daniil
Dec 02, 2013, 5:25 AM
Hi @michaeld,

The extension Update method is not going to work with a user control. No HTML element is associated with a user control in the rendered HTML output. So, nothing to update.

Also if some non-Ext.NET control contains Ext.NET controls, the Update method should not be used.

As a general rule, we recommend to avoid using the Update method where possible. It is better to wrap the non-Ext.NET controls in an Ext.NET container and use the Render or UpdateContent methods.

michaeld
Dec 02, 2013, 11:12 AM
I understand and agree, but let me draw attention again to the bug that causes the first characters to be removed from the stream.

Besides the fact that if you think this is an inappropriate usage, it is easy to test and exception at runtime with a message (certainly in debug mode).

Daniil
Dec 10, 2013, 3:52 AM
Thank you for the suggestion.

The following has been added to the Update method.

if (self is UserControl || self is PlaceHolder)
{
throw new System.Exception(string.Format("The extension Update method is not supposed to be called on UserControl or PlaceHolder (ID is '{0}'). Please wrap it an Ext.NET container and call its Render method.", self.ID));
}

if (Ext.Net.Utilities.ControlUtils.FindControls<BaseControl>(self).Count > 0)
{
throw new System.Exception(string.Format("The extension Update method is not supposed to be called on control (ID is '{0}') if it contains Ext.NET control(-s). Please wrap it an Ext.NET container and call its Render method.", self.ID));
}