RadControls for ASP.NET AJAX This topic demonstrates a possible scenario of RadAjaxManager updates controls from a composite control. It is important to set IDs of instantiated controls as well as adding them into controls collection. A necessary AJAX setting could be added at CreateChildControls method, however this must be done after controls are added into corresponding controls collection.
The example below includes a single RadAjaxManager control on the page. Here is the code-behind:
CopyC#
TestComposite Tst1;
protected void Page_Load(object sender, EventArgs e)
{
Tst1 = new TestComposite(RadAjaxManager1, "1");
Tst1.ID = "tst1";
this.form1.Controls.Add(Tst1);
}
protected void RadAjaxManager1_AjaxRequest(object sender, Telerik.Web.UI.AjaxRequestEventArgs e)
{
Tst1.controLbl.Text = Tst1.controTB.Text;
}
CopyVB
Private Tst1 As TestComposite
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Tst1 = New TestComposite(RadAjaxManager1, "1")
Tst1.ID = "tst1"
Me.form1.Controls.Add(Tst1)
End Sub
Protected Sub RadAjaxManager1_AjaxRequest(ByVal sender As Object, ByVal e As Telerik.Web.UI.AjaxRequestEventArgs)
Tst1.controLbl.Text = Tst1.controTB.Text
End SubAnd the composite control class:
CopyC#
public class TestComposite : CompositeControl
{
private Telerik.Web.UI.RadAjaxManager m_radAm;
private string m_UniqueId;
public TextBox MyTxt;
public Label MyLbl;
public TestComposite(RadAjaxManager radAm, string UniqueId)
{
m_radAm = radAm;
m_UniqueId = UniqueId;
}
protected override void RecreateChildControls()
{
EnsureChildControls();
}
protected override void CreateChildControls()
{
MyTxt = new TextBox();
MyLbl = new Label();
MyLbl.ID = "Lbl_" + m_UniqueId;
MyTxt.ID = "Txt_" + m_UniqueId;
MyLbl.Text = "LabelText";
this.Controls.Add(MyTxt);
this.Controls.Add(MyLbl);
MyTxt.Attributes.Add("onBlur", m_radAm.GetAjaxEventReference(MyTxt.ClientID));
m_radAm.AjaxSettings.AddAjaxSetting(m_radAm, MyLbl);
}
public TextBox controTB
{
get
{
return MyTxt;
}
}
public Label controLbl
{
get
{
return MyLbl;
}
}
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
MyTxt.RenderControl(output);
MyLbl.RenderControl(output);
}
}
CopyVB
Public Class TestComposite
Inherits CompositeControl
Private m_radAm As Telerik.Web.UI.RadAjaxManager
Private m_UniqueId As String
Public MyTxt As TextBox
Public MyLbl As Label
Public Sub New(ByVal radAm As RadAjaxManager, ByVal UniqueId As String)
m_radAm = radAm
m_UniqueId = UniqueId
End Sub
Protected Overrides Sub RecreateChildControls()
EnsureChildControls()
End Sub
Protected Overrides Sub CreateChildControls()
MyTxt = New TextBox()
MyLbl = New Label()
MyLbl.ID = "Lbl_" + m_UniqueId
MyTxt.ID = "Txt_" + m_UniqueId
MyLbl.Text = "LabelText"
Me.Controls.Add(MyTxt)
Me.Controls.Add(MyLbl)
MyTxt.Attributes.Add("onBlur", m_radAm.GetAjaxEventReference(MyTxt.ClientID))
m_radAm.AjaxSettings.AddAjaxSetting(m_radAm, MyLbl)
End Sub
Public ReadOnly Property controTB() As TextBox
Get
Return MyTxt
End Get
End Property
Public ReadOnly Property controLbl() As Label
Get
Return MyLbl
End Get
End Property
Protected Overrides Sub Render(ByVal output As HtmlTextWriter)
MyBase.Render(output)
MyTxt.RenderControl(output)
MyLbl.RenderControl(output)
End Sub
End Class
See Also