Welcome Guest Search | Active Topics | Sign In | Register

Callback was initially dynamically loaded Options
Mike Eyal
Posted: Tuesday, February 9, 2010 10:00:15 PM
Rank: Member
Groups: Member

Joined: 10/19/2009
Posts: 11
Hi,

I have posted about this topic before - I have followed the demo project implementation but I am still having the error about "Callback was initially dynamically loaded, but wasn't loaded for this callback". Could you please help?
My sequence of events are

1. A user clicks on a tab in a tab strip
2. This executes a Callback Panel Execute Event
3. A user control is loaded and added to a div in the Execute Event
4. The error occurs when executing a callback in the user control.

My code is as follows

Loading the User Control

Code: C#
private void Page_Init(object sender, System.EventArgs e)
        {

            if (Session["Control"] != null)
            {
                string currentPath = Session["Control"].ToString();
                if (currentPath != null)
                    LoadCustomControl(currentPath);
            }

        }

protected void cbPanel_Execute(object sender, CallbackEventArgs e)
        {
            if (e.TriggerControlID == null)
            {
                
                LoadCustomControl(e.Parameter);
            }
           
        }
        private void LoadCustomControl(string container)
        {
            var cntrlPath = "Controls/";

            switch (container)
            {
                case "ISIGN":
                    cntrlPath += "ISignDesigner.ascx";
                    iSignContainer.Controls.Add(Page.LoadControl(cntrlPath));
                    break;
                case "WESIGN":
                    cntrlPath += "WeSignDesigner.ascx";
                    weSignContainer.Controls.Add(Page.LoadControl(cntrlPath));
                    break;
            }
            Session["Control"] = container;

        }


My HTML

Code: HTML/ASPX
<div style="position: relative; top: 1px; z-index: 0;" onclick="hideAllWizControls();">
                                <eo:TabStrip ID="tsMain" runat="server" ControlSkinID="None" MultiPageID="mpMain"
                                    SelectedIndex="0">
                                    <LookItems>
                                        <eo:TabItem Height="26" ItemID="_Default" HoverStyle-CssText="cursor:hand; background:white; border-bottom-color:black;border-bottom-style:none;border-left-color:black;border-left-style:solid;border-left-width:1px;border-right-style:none;border-top-color:black;border-top-style:solid;border-top-width:1px; color:#1b5071; padding-left:8px; padding-right:8px;"
                                            NormalStyle-CssText="background-image: url('img/charlie/menu/mItemBack.gif'); background-repeat: repeat-x;border-bottom-color:black;border-bottom-style:solid;border-bottom-width:1px;border-left-color:black;border-left-style:solid;border-left-width:1px;border-right-style:none;border-top-color:black;border-top-style:solid;border-top-width:1px; padding-left:8px; padding-right:8px; color:white;"
                                            SelectedStyle-CssText="background: white; border-bottom-color:black;border-bottom-style:none;border-left-color:black;border-left-style:solid;border-left-width:1px;border-right-style:none;border-top-color:black;border-top-style:solid;border-top-width:1px; padding-left:8px; padding-right:8px; color:#1b5071;">
                                        </eo:TabItem>
                                    </LookItems>
                                    <TopGroup>
                                        <Items>
                                            <eo:TabItem ItemID="Documents" Text-Html="My Documents" OnClickScript="region ='myDocuments'; if (getRowCount('divInbox') >= 1) { showWizardGroup('mdi'); }"
                                                ExpandedStyle-CssText="background-color:white;border-bottom-color:black;border-bottom-style:solid;border-bottom-width:1px;border-left-color:black;border-left-style:solid;border-left-width:1px;border-right-color:black;border-right-style:solid;border-right-width:1px;border-top-color:black;border-top-style:solid;border-top-width:1px;color:black;padding-left:5px;padding-right:5px;"
                                                Selected="True">
                                            </eo:TabItem>
                                            <eo:TabItem ItemID="ISign" OnClickScript="eo_Callback('eoCBPISignLoad', 'ISIGN');"
                                                Text-Html="I Sign" Selected="False">
                                            </eo:TabItem>
                                            <eo:TabItem ItemID="WeSign" OnClickScript="eo_Callback('eoCBPWeSignLoad', 'WESIGN');"
                                                Text-Html="We Sign" Selected="False">
                                            </eo:TabItem>
                                            <eo:TabItem ItemID="FormFiller" OnClickScript="if (UpdateFormFiller) {UpdateFormFiller();}region = 'formFiller';"
                                                Text-Html="Form Filler" Selected="False">
                                            </eo:TabItem>
                                            <eo:TabItem ItemID="View" Text-Html="View Document" OnClickScript="region = 'viewDocument';"
                                                NormalStyle-CssText="border-right-color:black;border-right-style:solid;border-right-width:1px;"
                                                HoverStyle-CssText="border-right-color:black;border-right-style:solid;border-right-width:1px;"
                                                SelectedStyle-CssText="border-right-color:black;border-right-style:solid;border-right-width:1px;"
                                                Selected="False">
                                            </eo:TabItem>
                                        </Items>
                                    </TopGroup>
                                </eo:TabStrip>
                            </div>
                            <div style="min-height: 543px; width: 920px; background: white; border: solid 1px black;">
                                <eo:MultiPage ID="mpMain" runat="server" Height='100%' Width='920px' BackColor="White"
                                    SelectedIndex="0">
                                    <eo:PageView ID="pvDocuments" runat="server" Width="920px">
                                        <uc10:MyDocuments ID="MyDocuments1" runat="server" />
                                    </eo:PageView>
                                    <eo:PageView ID="pvISign" runat="server" Width="920px">
                                    <eo:CallbackPanel ID="eoCBPISignLoad" runat="server" SafeGuardUpdate="False" QueueMode="KeepLast" OnExecute="cbPanel_Execute" ClientSideAfterUpdate="OnAfterControlLoaded">
                                        <div id="iSignContainer" style="width: 912px; height: 740px; padding: 4px 4px 4px 4px;" runat="server">
                                            
                                        </div>
                                        </eo:CallbackPanel>
                                    </eo:PageView>
                                    <eo:PageView ID="pvWeSign" runat="server" Width="920px" Height="480px">
                                     <eo:CallbackPanel ID="eoCBPWeSignLoad" runat="server" SafeGuardUpdate="False" QueueMode="KeepLast" OnExecute="cbPanel_Execute" ClientSideAfterUpdate="OnAfterControlLoaded">
                                        <div id="weSignContainer" runat="server" style="width: 912px; height: 740px; padding: 4px 4px 4px 4px;">
                                           
                                        </div>
                                        </eo:CallbackPanel>
                                    </eo:PageView>
                                    <eo:PageView ID="pvFormFiller" runat="server" Width="920px" Height="480px">
                                        <div style="width: 912px; height: 740px; padding: 4px 4px 4px 4px;">
                                            <uc7:FormFillerDesigner ID="FormFillerDesigner1" runat="server" />
                                        </div>
                                    </eo:PageView>
                                    <eo:PageView ID="pvView" runat="server" Width="920px" Height="480px">
                                        <div style="width: 912px; height: 740px; padding: 4px 4px 4px 4px;">
                                            <uc1:ViewDocument ID="ViewDocument1" runat="server" />
                                        </div>
                                    </eo:PageView>
                                </eo:MultiPage>
                            </div>



Cheers

Mike
eo_support
Posted: Wednesday, February 10, 2010 8:37:01 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

Your code looks fine to us except that you might be loading the control twice during callback, once in Page_Init and once inside your cbPanel_Execute. This needs to be avoided.

Thanks!
Mike Eyal
Posted: Thursday, February 11, 2010 12:20:28 AM
Rank: Member
Groups: Member

Joined: 10/19/2009
Posts: 11
Hi,

I have tried to implement your solution without any luck so I have created a simple sample project demonstrating the issue, it is as follows (I am using version 7.0.43.2)

Default.aspx



Code: HTML/ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="DynamicCallbacks._Default" %>

<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>

<!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>
    <script type="text/javascript">
        function OnAfterControlLoaded(cb, extraData) {
            eo_Callback('CallbackPanel1');
        };
    
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <eo:CallbackPanel ID="eoCBPISignLoad" runat="server" SafeGuardUpdate="False" QueueMode="KeepLast" OnExecute="cbPanel_Execute" ClientSideAfterUpdate="OnAfterControlLoaded">
                                        <div id="iSignContainer" runat="server">
                                            
                                        </div>
                                        </eo:CallbackPanel>
        <input id="Button1" type="button" value="Click Me" onclick="eo_Callback('eoCBPISignLoad', 'ISIGN');" />   
                                        
    </div>
    </form>
</body>
</html>


Default.aspx.cs

Code: C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EO.Web;

namespace DynamicCallbacks
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
        private void Page_Init(object sender, System.EventArgs e)
        {
            
        }
        protected void cbPanel_Execute(object sender, CallbackEventArgs e)
        {

            LoadCustomControl(e.Parameter);

        }
        private void LoadCustomControl(string container)
        {
            switch (container)
            {
                case "ISIGN":
                    iSignContainer.Controls.Add(Page.LoadControl("ISignDesigner.ascx"));
                    break;
                
            }
            

        }
    }
}


ISignDesigner.ascx

Code: HTML/ASPX
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ISignDesigner.ascx.cs" Inherits="DynamicCallbacks.ISignDesigner" %>
<%@ Register Assembly="EO.Web" Namespace="EO.Web" TagPrefix="eo" %>
<eo:CallbackPanel ID="CallbackPanel1" runat="server" Height="150px" 
    Width="200px" onexecute="CallbackPanel1_Execute">
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</eo:CallbackPanel>


ISignDesigner.ascx.cs

Code: C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DynamicCallbacks
{
    public partial class ISignDesigner : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void CallbackPanel1_Execute(object sender, EO.Web.CallbackEventArgs e)
        {
            this.Label1.Text = "Done";
        }
    }
}


Thank you for your support so far

Cheers

Mike
eo_support
Posted: Thursday, February 11, 2010 10:48:49 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You misunderstood our previous reply. In order to use dynamic loading, you must ensure the page structure is identical before and after the postback. This is a general rule for ASP.NET and it has nothing to do with our controls.

Your original code is wrong because:

1. Before the post back you loaded your control in Page_Init. So you have loaded once before post back (there are one instance of your control in the page);
2. After the post back you loaded your control in Page_Init and Callback_AfterExecute. So you have loaded twice after post back (there are now two instances of your controls in the page);

So the page structure is different before and after (one instance vs. two instances). Thus it is wrong.

Your new code is also wrong because:

1. Before the post back you did not load your control. So you have loaded your control zero times before post back (zero instance);
2. After the post back you loaded your control in Callback_AfterExecute. So you have loaded once after post back (one instance).

Thus the page structure is also different before and after. (Zero instance vs. One instance).

To correct the problem, you must:
1. Keep the code inside your Page_Init;
2. Modify your LoadCustomControl so that no matter how many times you call it, you will only have ONE instance in your page. This usually means you need to clear all previous loaded control before you load and add a new one.

Hope this helps.

Thanks!
Mike Eyal
Posted: Sunday, February 14, 2010 8:01:50 PM
Rank: Member
Groups: Member

Joined: 10/19/2009
Posts: 11
Thank you, I didn't understand the rules for dynamically loading a control, but I do now - the code is working.

Cheers

Mike
eo_support
Posted: Monday, February 15, 2010 9:52:41 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Thanks for the update. Great to hear that it's working!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.