RadControls for ASP.NET AJAX In some cases you need to add AJAX pairs dynamically (at runtime). You should always do this in a Page event handler, which is executed each time during the page lifecycle (Page_Load, Page_PreRender) so that the control could be ajaxified when the page is initially loaded.
Note |
|---|
Note that you need to assure that the controls that take part in the AJAX pair are available on the page! |
Note |
|---|
You cannot add AJAX settings dynamically in the Page_Init event. It is too early in the page lifecycle since the RadAjaxManager is not created yet. |
The example below demonstrates how to ajaxify a Button dynamically to toggle the visibility of an Image:
CopyASPX
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Panel ID="Panel1" runat="server" Height="95px">
<asp:Image ID="Image1" runat="server" ImageUrl="http://www.Telerik.com/images/Homepage/TelerikLogo.gif" />
</asp:Panel>And in the code-behind:
CopyC#
protected void Page_Load(object sender, EventArgs e)
{
RadAjaxManager1.AjaxSettings.AddAjaxSetting(Button1, Panel1, null);
}
protected void Button1_Click(object sender, EventArgs e)
{
Image1.Visible = !Image1.Visible;
}
CopyVB.NET
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
RadAjaxManager1.AjaxSettings.AddAjaxSetting(Button1, Panel1, Nothing)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Image1.Visible = Not Image1.Visible
End Sub