New to Telerik UI for ASP.NET AJAX? Start a free 30-day trial
Add the AjaxManager Programmatically
Environment
Product | Progress® Telerik® UI for ASP.NET AJAX AjaxManager |
Description
How can I programmatically create an AjaxManager control?
Solution
To achieve the desired scenario, you need to create the AjaxManager in the Page_Init
event on a later stage.
The following example demonstrates how to define the AjaxManager control.
C#
protected void Page_Init(object sender, EventArgs e)
{
RadAjaxManager manager = new RadAjaxManager();
manager.ID = "RadAjaxManager1";
this.Page.Form.Controls.Add(manager);
}
Now you need to access the RadAjaxManager
instance by calling the GetCurrent()
static method of the RadAjaxManager
class. Note that if you are creating the ScriptManager
dynamically as well, you have to add it to the Page.Form.Controls
collection before the RadAjaxManager
control.
Server-Side
C#
protected void Page_Load(object sender, EventArgs e)
{
RadAjaxManager manager = RadAjaxManager.GetCurrent(Page);
}
JavaScript
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function GetAjaxManager() {
var manager = $find("<%= RadAjaxManager.GetCurrent(Page).ClientID %>")
}
</script>
</telerik:RadCodeBlock>