Wednesday, March 21, 2012

Loading an Atlas enabled UserControl Dynamically. Urgent!

Hello,

I have 2 buttons within an UpdatePanel (for the menu) and another UpdatePanel (for the Content) where I load a control depending of the menu clicked.

MyControl1.ascx and MyControl2.ascx both content an UpdatePanel too.

Default.aspx:

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default.aspx.cs"Inherits="_Default"%>

<html>

<headid="Head1"runat="server">

<title></title>

<Atlas:ScriptManagerID="ScriptManager1"runat="server"EnablePartialRendering="true"/>

</head>

<body>

<formid="form1"runat="server">

<div>

<Atlas:updatepanelid="UpdatePanel1"runat="server"mode="Conditional"rendermode="Inline">

<contenttemplate>

<asp:ButtonID="Button1"runat="server"Text="Button"OnClick="Button1_Click"/>

<asp:ButtonID="Button2"runat="server"Text="Button"OnClick="Button2_Click"/>

</contenttemplate>

</Atlas:updatepanel>

<br/>

<Atlas:updatepanelid="UpdatePanel2"runat="server"mode="Conditional"rendermode="Inline">

<Triggers>

<Atlas:ControlEventTriggerControlID="Button1"EventName="Click"/>

<Atlas:ControlEventTriggerControlID="Button2"EventName="Click"/>

</Triggers>

<contenttemplate>

<asp:PlaceHolderID="PlaceHolder1"runat="server"></asp:PlaceHolder>

</contenttemplate>

</Atlas:updatepanel>

</div>

</form>

</body>

</html>

Default.aspx.cs:

using System;

using System.Text;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

publicpartialclass _Default : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

}

protectedoverridevoid OnInit(EventArgs e)

{

base.OnInit(e);

if (Session["ContentControl"] !=null)

{

Control c = LoadControl(Session["ContentControl"].ToString());

PlaceHolder1.Controls.Add(c);

}

}

protectedvoid Button1_Click(object sender,EventArgs e)

{

Session["ContentControl"] ="/MyContent1.ascx";

}

protectedvoid Button2_Click(object sender,EventArgs e)

{

Session["ContentControl"] ="/MyContent2.ascx";

}

}

MyContent1.ascx:

<%@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="MyContent1.ascx.cs"Inherits="MyContent1"%>

<IGI:updatepanelid="Updatepanel1"runat="server"mode="Conditional"rendermode="Inline">

<contenttemplate>

MyContent1

</contenttemplate>

</IGI:updatepanel>

MyContent2.ascx:

<%@dotnet.itags.org.ControlLanguage="C#"AutoEventWireup="true"CodeFile="MyContent2.ascx.cs"Inherits="MyContent2"%>

<IGI:updatepanelid="Updatepanel1"runat="server"mode="Conditional"rendermode="Inline">

<contenttemplate>

MyContent2

</contenttemplate>

</IGI:updatepanel>

My problem is I have to click twice on a button for the Content control to load because the OnInit is executed before theButton1_Click.( the session is not updated yet when the OnInit is executed );

Anybody has an idea to achived this in One Click??

Many Thanks,

Yann

Did anyone every respond to you on this question? I am having the same problem, and I could only solve it (kind of) by using a master page.

I wrapped the ContentPlaceHolder in the master page inside an UpdatePanel, and in my actual page, I put another PlaceHolder for holding my dynamically created user control (or other type of control based on my portal's configuration).

I would like to know if anyone ever answers this, and I would also like to be able to use WebParts in this scenario, which I have NEVER gotten to work with Atlas and dynamic user controls reliably.

No comments:

Post a Comment