HOW-TO Get reference to controls inside tabstrip templates (v1.x only)SOLUTIONWhen you have server controls nested inside a RadTabStrip template you cannot directly access them in the code-behind. If you have the following set-up:<radTS:RadTabStrip ID="RadTabStrip1" Runat="server"><TabCollection> <radTS:Tab ID="Tab1" Text="Tab 1"> <ContentTemplate> <asp:TextBox ID="TextBox1" Runat="server" Text="Text 1 Text"></asp:TextBox> </ContentTemplate> </radTS:Tab> <radTS:Tab ID="Tab2" Text="Tab 2"> <ContentTemplate> <asp:TextBox ID="TextBox2" Runat="server" Text="Text 2 Text"></asp:TextBox> </ContentTemplate> </radTS:Tab></TabCollection></radTS:RadTabStrip>then if you try the following in your code-behind: protected Telerik.WebControls.RadTabStrip RadTabStrip1;protected System.Web.UI.WebControls.TextBox TextBox1; private void Page_Load(object sender, System.EventArgs e){ TextBox1.Text = "Set from code-behind";}
protected Telerik.WebControls.RadTabStrip RadTabStrip1;protected System.Web.UI.WebControls.TextBox TextBox1;
private void Page_Load(object sender, System.EventArgs e){ TextBox1.Text = "Set from code-behind";}
you will get a System.NullReferenceException exception.
In order to properly access a control inside a template you must use the RadTabStrip's FindControl() method. So the upper function should become like this:
private void Page_Load(object sender, System.EventArgs e){ TextBox1 = (System.Web.UI.WebControls.TextBox)RadTabStrip1.FindControl("TextBox1"); TextBox1.Text = "Set from code-behind";}
The FindControl() method returns a reference to a Control class so you must properly typecast the returned value to the class you need.
For more information refer to the FindControl method in the RadTabStrip API reference.
Resources Buy Try