[CLOSED] Event Catch-Up bug w/BorderLayout

  1. #1

    [CLOSED] Event Catch-Up bug w/BorderLayout



    Below is an example of what I think is a bug in the BorderLayout.

    When a panel is added to a region in code-behind, the panel and its contents do not get their events called until the pre-render stage of the page. If the panel is defined in the markup however, it all works right.

    You will see that the TextField control in the center panel does not handle postback data or viewstate right, but the one in the south panel works right.


    <%@ Page Language="C#" CodeBehind="Test2.aspx.cs" Inherits="Sandbox.FormData.Test2" %>
    <%@ 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>Untitled Page</title>
      </head>
      <body>
        <form id="_form" runat="server">
          <ext:ScriptManager runat="server" />
          <ext:ViewPort runat="server" ID="_viewPort">
            <Body>
              <ext:BorderLayout runat="server" ID="_borderLayout">
                <South>
                  <ext:Panel runat="server" ID="_southPanel" Title="South Panel" Height="200" />
                </South>
              </ext:BorderLayout>
            </Body>  
          </ext:ViewPort>    
        </form>
      </body>
    </html>
    using System;
    using System.Collections;
    using System.Data;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    
    
    using Coolite.Ext.Web;
    using Cool=Coolite.Ext.Web;
    
    
    namespace Sandbox.FormData
    {
      public partial class Test2 : System.Web.UI.Page
      {
        private Cool.Panel _centerPanel = new Cool.Panel{Title="Center Panel"};
        
        #region Init Event
        protected override void OnInit(EventArgs e)
        {
          Init_Panel(_centerPanel);
          Init_Panel(_southPanel);
          
          _borderLayout.Center.Items.Add(_centerPanel);
          
          base.OnInit(e);
        }
        private void Init_Panel(Cool.Panel panel)
        {
          Cool.FormLayout formLayout  = new Cool.FormLayout();
          Cool.Button     save        = new Cool.Button{AutoPostBack=true};
          MyTextField     myTextField = new MyTextField();
          Cool.Anchor     anchor      = new Anchor(myTextField);
          anchor.Horizontal = "-5";
    
    
          switch(panel.Title)
          {
            case "Center Panel" :
            {
              myTextField.ID = "CenterTextField";
              myTextField.FieldLabel = "Center Text";
              save.Click += new EventHandler(OnClick_Save_Center);
              save.Text = "Center Save";
            } break;
    
    
            case "South Panel" :
            {
              myTextField.ID = "SouthTextField";
              myTextField.FieldLabel = "South Text";
              save.Click += new EventHandler(OnClick_Save_South);
              save.Text = "South Save";
            } break;
          }
          formLayout.Anchors.Add(anchor);
          panel.BodyControls.Add(formLayout);      
          panel.Buttons.Add(save);
        }
        #endregion Init Event
        
        #region Save Event
        void OnClick_Save_Center(object sender, EventArgs e) {OnSave("CenterTextField");}
        void OnClick_Save_South (object sender, EventArgs e) {OnSave("SouthTextField");}
        private void OnSave(string textFieldId)
        {
          string txt = ((MyTextField)Page.FindControl(textFieldId)).Text;      
        }
        #endregion Save Event
        
        #region Misc Events
        protected override void OnLoad(EventArgs e)
        {
          base.OnLoad(e);
          Page p = _centerPanel.Page; // centerPanel.Page==null.  It does not know its on the page yet.  MyTextField.Init not called yet
        }
        protected override void OnPreRender(EventArgs e)
        {
          base.OnPreRender(e);
          Page p = _centerPanel.Page; // centerPanel.Page==null.  It does not know its on the page yet.  MyTextField.Init not called yet
        }
        protected override void Render(HtmlTextWriter writer)
        {
          Page p = _centerPanel.Page; // now, centerPanel knows its on the page.  MyTextField.Init has finaly been called. 
          base.Render(writer);
        }
        #endregion Misc Events
      }
      internal class MyTextField : Cool.TextField
      {
        protected override void OnInit(EventArgs e)
        {
          base.OnInit(e);
        }
        protected override void LoadViewState(object state)
        {
          base.LoadViewState(state);
        }
        protected override bool LoadPostData(string postDataKey, System.Collections.Specialized.NameValueCollection postCollection)
        {
          return base.LoadPostData(postDataKey, postCollection);
        }
      }
    }
  2. #2

    RE: [CLOSED] Event Catch-Up bug w/BorderLayout



    FYI - Ive found an effective workaround for this bug that works in my scenario.

    Since I code exclusively in code-behind, I simply don't add the ViewPort to the page heirarchy until AFTER I have assigned and filled in all the Regions of the BorderLayout.

    Apparently when the ViewPort is added to the page control heirarchy, it properly initializes all BorderLayout Regions at that time. But if the ViewPort is already on the page, and you add a new Region to the BorderLayout, then the components in that region are not properly initialized. In this case, what happens is that when the page gets to the PreRender stage, the events 'catch-up', but calling the Init for the components in the new region at this stage is too late for them to be registered in the ControlState/ViewState properly.



  3. #3

    RE: [CLOSED] Event Catch-Up bug w/BorderLayout

    Hi,

    I am working on it. The fix will be committed soon
  4. #4

    RE: [CLOSED] Event Catch-Up bug w/BorderLayout

    Hi,

    The fix is committed to SVN. Please update

Similar Threads

  1. Replies: 0
    Last Post: Apr 19, 2012, 3:52 PM
  2. [CLOSED] Catch 404 Error
    By speedstepmem4 in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 13, 2012, 9:06 AM
  3. Click on disabled TextField - catch the event
    By AlexMaslakov in forum 1.x Help
    Replies: 1
    Last Post: Nov 14, 2011, 12:31 PM
  4. [CLOSED] TabPanel: catch event before closing a tab
    By RomualdAwessou in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Jul 13, 2010, 4:57 PM
  5. [CLOSED] Catch any failure
    By acrossdev in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Jul 23, 2009, 7:27 AM

Posting Permissions