In this article I will explain how to dynamically load ASP.Net UserControl using jQuery AJAX and add it to the ASP.Net page. I will also explain how to dynamically pass parameters to ASP.Net UserControl using jQuery AJAX
I have a simple UserControl with one ASP.Net Label control to display the message on the screen. We will load this UserControl using jQuery AJAX and also set its Label text.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="Message.ascx.cs" Inherits="Message" %>
<asp:Label ID="lblMessage" runat="server" Text="lblMessage"></asp:Label>
You will need to import the following namespaces
using System.IO;
using System.Web.Services;
Imports System.Web.Services
Imports System.IO
Below is the WebMethod that will accept the jQuery AJAX call and load the UserControl dynamically. The WebMethod accepts string parameter message which I use to set the Label Control inside the UserControl. Finally the UserControl returned as HTML string back to the page.
public static string LoadUserControl(string message)
    using (Page page = new Page())
        UserControl userControl = (UserControl)page.LoadControl("Message.ascx");
        (userControl.FindControl("lblMessage") as Label).Text = message;
        using (StringWriter writer = new StringWriter())
            HttpContext.Current.Server.Execute(page, writer, false);
            return writer.ToString();
<WebMethod()> _
Public Shared Function LoadUserControl(message As String) As String
    Using page As New Page()
        Dim userControl As UserControl = DirectCast(page.LoadControl("Message.ascx"), UserControl)
        TryCast(userControl.FindControl("lblMessage"), Label).Text = message
        Using writer As New StringWriter()
            HttpContext.Current.Server.Execute(page, writer, False)
            Return writer.ToString()
        End Using
    End Using
End Function
Client Side Implementation
Below we are making an AJAX call to the server WebMethod and passing the message parameter which is the content of the HTML TextBox with ID message. On click of the HTML Button with ID demo jQuery AJAX loads the UserControl and appends it to the DIV with ID Content.
<html xmlns="">
<head runat="server">
    <script type="text/javascript" src=""></script>
    <script type = "text/javascript">
        $("#demo").live("click", function () {
                type: "POST",
                url: "MyPage.aspx/LoadUserControl",
                data: "{message: '" + $("#message").val() + "'}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (r) {
    <form id="form1" runat="server">
    <input type = "text" id = "message" />
    <input type = "button" id = "demo" value = "Load" />
    <div id = "Content">
How to load ASP.Net UserControl Dynamically using jQuery AJAX

Fetch and Display ASP.Net UserControl Dynamically using jQuery AJAX

Download Code