Welcome Guest Search | Active Topics | Sign In | Register

Handle Callback by Dynamically loaded UserControl Options
John Foley
Posted: Monday, March 8, 2010 2:57:31 PM
Rank: Member
Groups: Member

Joined: 9/6/2008
Posts: 29
Hi,

I found some posts on this but couldn't figure out if this is solution is possible from what I found. I have a page that will load from 1 to many user controls depending on a user's settings. The control I am having problems with has a callbackPanel in it and I'd like the user to be able to click a button and reload that content in the control. Since the userControl is loaded dynamically, It appears that the page can't find that control again to handle the callback. Is this possible? Here is a very simple example of what I'm trying to do:

Default6.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default6.aspx.vb" Inherits="Default6" %>

<!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">
<div>
<asp:Panel ID="pnlControl" runat="server" />
</div>
</form>
</body>
</html>

Default6.aspx.vb
Partial Class Default6
Inherits System.Web.UI.Page

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
Dim ttControl As UserControl = LoadControl("~/ttcontrols/eoSample.ascx")
pnlControl.Controls.Add(ttControl)
End If
End Sub

End Class

ttControls/eoSample.aspx
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="eoSample.ascx.vb" Inherits="ttcontrols_eoSample" %>
<%@ Register TagPrefix="eo" Namespace="EO.Web" Assembly="EO.Web" %>

<eo:CallbackPanel ID="cpTest" runat="server" LoadingHTML="Loading" Triggers="{ControlID:btnTest;Parameter:test}">

<asp:Button ID="btnTest" runat="server" Text="Save" /><br /><br />
<asp:Label ID="lblClicked" runat="server" Text="" />

</eo:CallbackPanel>

ttControls/eoSample.aspx.vb

Partial Class ttcontrols_eoSample
Inherits System.Web.UI.UserControl

Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

If Not Page.IsPostBack Then

End If

End Sub

Sub btnTest_Clicked(ByVal sender As Object, ByVal e As EventArgs)

lblClicked.Text = Now()

End Sub

End Class


Thanks for any information you can provide.
John Foley
Posted: Monday, March 8, 2010 3:34:09 PM
Rank: Member
Groups: Member

Joined: 9/6/2008
Posts: 29
I was actually able to get this to work partially by really looking closely at your sample project. The problem that I am having now is that I lose the value selected by the user in my radio button list. Is there anything else I need to do to make sure the control doesn't lose the selected value?
eo_support
Posted: Monday, March 8, 2010 4:20:07 PM
Rank: Administration
Groups: Administration

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

We won't be able to give you specific instruction on this because this is primarily a general ASP.NET programming issue. The basic rule for dynamic loading is you have to reload the same thing you loaded last time during the "Init" stage. Here is another post about the same issue:

http://www.essentialobjects.com/forum/postst4243_Callback-was-initially-dynamically-loaded.aspx

There are various ways for you to make sure you reload whatever you loaded last time. The sample used a hidden input field but you can use other means, for example, a Session variable. There is no specific rule on what to use. It is totally up to you.

Note you have to finish reload in or before the "Init" stage. Any stage after that such as "Load" or server event won't work. For example, if you were handing a Button click event inside your dynamically loaded control, obviously you have to have that control loaded before the event firing stage, otherwise ASP.NET won't find your button to call your handler.

Thanks!


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.