RadAjax for ASP.NET AJAX

RadControls for ASP.NET AJAX

The dynamic loading of user controls follows the same logic as in normal postback application. You can load custom user controls via AJAX requests by following the steps below:

  1. You need to have an appropriate container for it, for example ASP:Panel.

  2. Instantiate your user control in Page_Init or Page_Load and always recreate the last loaded User Control:

  3. Make sure you assign unique ID to the dynamically loaded User Control:

  4. Place the instance inside the controls collection of the container:

    CopyCS/VB
    Parent.Controls.Add(MyControl)
  5. Here is the code from a sample project:

CopyASPX
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<asp:Button ID="Button1" runat="server" Text="Load WebUserControl1.ascx" OnClick="Button1_Click" />
<asp:Button ID="Button2" runat="server" Text="Load WebUserControl2.ascx" OnClick="Button2_Click" />
<asp:Panel ID="Panel1" runat="server">
</asp:Panel>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="Button1">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Panel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
        <telerik:AjaxSetting AjaxControlID="Button2">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="Panel1" />
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>

And in the code-behind:

For full code working application you can check this example in RadAjax for ASP.NET AJAX Quick Start Framework:

http://demos.telerik.com/aspnet-ajax/Ajax/Examples/Common/LoadingUserControls/DefaultCS.aspx

See Also