Nov 03, 2008, 8:13 PM
[FIXED] [V0.7] Nested dynamic controls don't behave correctly in Page Cycle
I have been stuck on this for almost 5 hours today. I have a form that is populated with dynamic user controls. On a Postback or AjaxEvent, the dynamic controls are playing catch up way too late in the page life cycle. The Init/Load events of the dynamic control are fired AFTER the page's Load and button's AjaxEvent are fired. I am adding the dynamic controls during Page Init. With standard ASP.NET, dynamic controls should play catch up as soon as they are added to the page.
Here's a small code example. Make sure to run this in debug mode and just pay attention to the order of events during the tool button click.
ASPX:
Here's a small code example. Make sure to run this in debug mode and just pay attention to the order of events during the tool button click.
ASPX:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="DynamicControls.aspx.vb"
Inherits="Coolite.DynamicControls" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<script runat="server">
</script>
<ext:ScriptManager ID="ScriptManager1" runat="server">
</ext:ScriptManager>
<ext:Panel runat="server" ID="pnlExt" Title="Dynamic Control Test">
<TopBar>
<ext:Toolbar runat="server">
<Items>
<ext:ToolbarButton runat="server" ID="btnTest" Text="Test">
<AjaxEvents>
<Click OnEvent="btnClicked">
<EventMask ShowMask="true" Msg="Working..." />
</Click>
</AjaxEvents>
</ext:ToolbarButton>
</Items>
</ext:Toolbar>
</TopBar>
<Body>
<ext:FormLayout runat="server" ID="pnlForm">
</ext:FormLayout>
</Body>
</ext:Panel>
</form>
</body>
</html>
VBImports Coolite.Ext.Web
Partial Public Class DynamicControls
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim newAnchor As New Anchor
Me.pnlForm.Anchors.Add(newAnchor)
Dim pnl As New Panel()
newAnchor.Items.Add(pnl)
pnl.BodyControls.Add(New DummyControl)
If Debugger.IsAttached Then Debugger.Break()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Debugger.IsAttached Then Debugger.Break()
End Sub
Protected Sub btnClicked(ByVal sender As Object, ByVal e As AjaxEventArgs)
If Debugger.IsAttached Then Debugger.Break()
End Sub
End Class
Public Class DummyControl
Inherits Control
Implements IPostBackDataHandler
Private Sub Dummy_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
If Debugger.IsAttached Then Debugger.Break()
End Sub
Private Sub Dummy_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Debugger.IsAttached Then Debugger.Break()
End Sub
Public Function LoadPostData(ByVal postDataKey As String, ByVal postCollection As System.Collections.Specialized.NameValueCollection) As Boolean Implements System.Web.UI.IPostBackDataHandler.LoadPostData
If Debugger.IsAttached Then Debugger.Break()
End Function
Public Sub RaisePostDataChangedEvent() Implements System.Web.UI.IPostBackDataHandler.RaisePostDataChangedEvent
If Debugger.IsAttached Then Debugger.Break()
End Sub
End Class