Cast error

2 posts, 0 answers
  1. Eva
    Eva avatar
    50 posts
    Member since:
    Jun 2010

    Posted 17 May 2011 Link to this post

    I am getting the following cast error,
    Cannot cast 'RadPanelBar1.FindItemByValue("QuickSearch").FindControl("txtFirstName")' (which has an actual type of 'Telerik.Web.UI.RadTextBox') to 'System.Web.UI.WebControls.TextBox'

     

    protected void imSearch_Click(object sender, EventArgs e)

     

     

    {

     

     

    TextBox txtFirstName = (TextBox)RadPanelBar1.FindItemByValue("QuickSearch").FindControl("txtFirstName");

     

     

     

    }

     

    <telerik:RadPanelBar runat="server" ID="RadPanelBar1" Width="100%" ExpandMode="SingleExpandedItem" Skin="Windows7" >

     

     

    <Items>

     

     

    <telerik:RadPanelItem Text="Quick Search" Expanded="True" runat="server" >

     

     

    <Items>

     

     

    <telerik:RadPanelItem runat="server" Value="QuickSearch" BorderColor="Red" >

     

     

    <ItemTemplate>

     

     

     

    <asp:Label ID="lblSearch" style="text-align:center" runat="server" Text="First Name:" Font-Bold="True" />

     

     

     

    <telerik:RadTextBox ID="txtFirstName" runat="server" EmptyMessage="Search First Name" Skin="WebBlue" Width="130px"/>

     

    Can anybody tell me what I'm missing.

  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 18 May 2011 Link to this post

    Hello Eva,

    Since you are using the RadTextBox, you need to cast it as RadTextBox not as TextBox.
    C#:
    protected void Button1_Click(object sender, EventArgs e)
       {
           RadTextBox txtFirstName = (RadTextBox)RadPanelBarContratti.FindItemByValue("QuickSearch").FindControl("txtFirstName");
          
       }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top