I'm trying to load custom userControl in a panel in one of my DNNmodule. I placed a DropDownList and a Panel and when the DropDowList selection is changed i load the corresponding UserControl in the panel.
here is the ascx file
<%@ Control Codebehind="MyContainer.ascx.cs" Inherits="Test.MyContainer" Language="C#" %>
<%@ Register Assembly="RadAjax.Net2" Namespace="Telerik.WebControls" TagPrefix="radA" %>
<div class="module" style="float: left; width: 330px; height: 280px;">
<asp:Label ID="Label2" runat="server" Font-Bold="True" Style="padding-right: 21px;">interfaces:</asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" Width="120px">
</asp:ListItem>
<asp:ListItem Text="usercontrol1" Value="usercontrol1" Selected=""True>
</asp:ListItem>
<asp:ListItem Text="usercontrol2" Value="usercontrol2">
</asp:ListItem>
</asp:DropDownList>
<br />
<br />
<br />
<hr />
<br />
<asp:Label ID="lblStatus" runat="server" Style="color: green;" Width="224px"></asp:Label>
<asp:Panel ID="Panel1" runat="server" Height="100%" Width="100%">
</asp:Panel>
</div>
<radA:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<radA:AjaxSetting AjaxControlID="DropDownList1">
<UpdatedControls>
<radA:AjaxUpdatedControl ControlID="Panel1" LoadingPanelID="LoadingPanel1" />
</UpdatedControls>
</radA:AjaxSetting>
</AjaxSettings>
</radA:RadAjaxManager>
<radA:AjaxLoadingPanel ID="LoadingPanel1" runat="server" InitialDelayTime="0">
<asp:Image ID="Image1" runat="server" AlternateText="Loading" BorderWidth="0px" ImageUrl="~/RadControls/AJAX/Skins/Default/loading1.gif" />
</radA:AjaxLoadingPanel>
Telerik Admin
Posted on Sep 15, 2006
(permalink)
Hi mathieu,
Thank you for your interest in our controls.
I am not sure what the problem in your case might be. Do you get an error loading your controls?
We have a good help article regarding
loading user controls with AJAX. It has helped a lot of people so just review it and let us know if you need more help.
Greetings,
Konstantin Petkov
the
telerik team
Reply
Benoist
Posted on Dec 17, 2008
(permalink)
Hello,
Well i tried to do the same thing on a DNN portal.
| <asp:Button ID="Button1" runat="server" Text="Load WebUserControl1.ascx" /> |
| <br /> |
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="Button1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="Panel1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <asp:Panel ID="Panel1" runat="server"></asp:Panel> |
This is the error i'm receiving.
A critical error has occurred.
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
The custom control that is loaded doesnt contain code blocks.
Reply
Telerik Admin
Posted on Dec 17, 2008
(permalink)
Hi Benoist,
Please review the
following help topic which elaborates on this error. Test the provided approach and let us know if this helps.
Kind regards,
Maria Ilieva
the Telerik team
Check out
Telerik Trainer, the state of the art learning tool for Telerik products.
Reply
Benoist
Posted on Dec 18, 2008
(permalink)
Well i had a look at that help topic, but i dont know where to put the RadCodeBlock in the DNN source. Although I think that putting RadCodeBlock's in DNN source code is not the right solution.
Another thing that to is really strange is the fact that RadAjaxPanel can work just fine with reloading PanelContents. This means that the desired functionality can be achieved by using RadAjaxPanel but it doesn't work with the RadAjaxManager. I'll give an example of this case.
This will work:
| <telerik:RadAjaxPanel ID="Panel1" runat="server"> |
| <asp:Button ID="Button1" runat="server" Text="Load WebUserControl1.ascx" OnClick="Button1_Click"/> |
| </telerik:RadAjaxPanel> |
This wont work:
| <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" EnablePageHeadUpdate="false" EnableAJAX="true"> |
| <AjaxSettings> |
| <telerik:AjaxSetting AjaxControlID="Button1"> |
| <UpdatedControls> |
| <telerik:AjaxUpdatedControl ControlID="Panel1" /> |
| </UpdatedControls> |
| </telerik:AjaxSetting> |
| </AjaxSettings> |
| </telerik:RadAjaxManager> |
| <asp:Button ID="Button1" runat="server" Text="Load WebUserControl1.ascx" OnClick="Button1_Click"/> |
| <telerik:RadAjaxPanel ID="Panel1" runat="server"> |
| </telerik:RadAjaxPanel> |
As you can see in this example, in the working case the button is inside the RadAjaxPanel and in the non-working case the button is above the RadAjaxPanel. The reason why i want the second case to work, is that i don't always want to put the button near the panel. But why is RadAjaxPanel capable of parsing UserControls and RadAjaxManager isn't?
Greetings Benoist
Reply
Evert van Es
Posted on Dec 18, 2008
(permalink)
Post deleted
Reply
Benoist
Posted on Dec 18, 2008
(permalink)
Well i've just found a fix for the whole situation, but that makes your RadAjaxManager obsolete.
My code looks like this now:
| <asp:Button ID="Button1" runat="server" Text="Load WebUserControl1.ascx" OnClick="Button1_Click"/> |
| |
| <telerik:RadAjaxPanel ID="Panel1" runat="server"> |
| </telerik:RadAjaxPanel> |
In the code behind the button get's a client onclick which is as follows:
| protected void Page_Load(object sender, EventArgs e) |
| { |
| Button1.Attributes.Add("onclick", "AjaxNS.AR(this.name, '', '" + Panel1.ClientID + "', event); return false;"); |
| } |
The button's serverside OnClick triggers the following code:
| protected void Button1_Click(object sender, EventArgs e) |
| { |
| LoadUserControl("WebUserControl1.ascx"); |
| } |
| |
| public void LoadUserControl(string controlName) |
| { |
| if (LatestLoadedControlName != null) |
| { |
| Control previousControl = Panel1.FindControl(LatestLoadedControlName.Split('.')[0]); |
| if (previousControl != null) |
| { |
| this.Panel1.Controls.Remove(previousControl); |
| } |
| } |
| string userControlID = controlName.Split('.')[0]; |
| Control targetControl = Panel1.FindControl(userControlID); |
| if (targetControl == null) |
| { |
| Control userControl = (Control)this.LoadControl(controlName); |
| //slashes and tildes are forbidden |
| userControl.ID = userControlID.Replace("/", "").Replace("~", ""); |
| this.Panel1.Controls.Add(userControl); |
| LatestLoadedControlName = controlName; |
| } |
| } |
| |
| private string LatestLoadedControlName |
| { |
| get |
| { |
| return (string)ViewState["LatestLoadedControlName"]; |
| } |
| set |
| { |
| ViewState["LatestLoadedControlName"] = value; |
| } |
| } |
This works just fine. But i still dont get why your RadAjaxManager doesn't do the same thing...
Greeting Benoist
Reply