FindControl doesn't work

3 posts, 0 answers
  1. Joey
    Joey avatar
    32 posts
    Member since:
    Feb 2008

    Posted 08 May 2008 Link to this post

    The FindControl() method doesn't work for RadToolbars.

    This is exploding in the code behind:
    RadNumericTextBox resultCount = (RadNumericTextBox)DeploymentHistoryToolbar.FindControl("ResultTemplate").FindControl("txtResultCount");

    Here is the front end code:


    <

    telerik:RadToolbar ID="DeploymentHistoryToolbar" runat="server" AutoPostBack="true"

    ShortcutKey="Control" RadControlsDir="~/RadControls" DisplayEnds="true">

    <Items>

    <telerik:RadToolbarButton ID="btnRefresh" ToolTip="Refresh" DisplayType="ImageOnly"

    ButtonImage="../../../../../images/Refresh.gif" Text="Refresh" CommandName="Refresh"

    AccessKey="r" />

    <telerik:RadToolBarButton ID="ResultTemplate" runat="server" ToolTip="Enter -1 to show all rows.">

    <ItemTemplate>&nbsp;

    <b class="toolBarText">Rows to show:</b>&nbsp;

    <telerik:RadNumericTextBox ID="txtResultCount" runat="server" InvalidStyle-BackColor="red" NumberFormat-DecimalDigits="0" Value="-1" Width="60px">

    </telerik:RadNumericTextBox>&nbsp;&nbsp;

    </ItemTemplate>

    </telerik:RadToolBarButton>

    </Items>

    </

    telerik:RadToolbar>

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

    Posted 09 May 2008 Link to this post

    Hi Joey,

    Try accessing the RadNumericTextBox as shown below.

    ASPX:
       <telerik:RadToolBar ID="RadToolBar1" runat="server" OnButtonClick="RadToolBar1_ButtonClick"
                <Items> 
                  <telerik:RadToolBarButton > 
                   <ItemTemplate> 
                       <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server"
                       </telerik:RadNumericTextBox> 
                   </ItemTemplate> 
                  </telerik:RadToolBarButton> 
                </Items> 
                </telerik:RadToolBar> 


    CS:
    protected void RadToolBar1_ButtonClick(object sender, RadToolBarEventArgs e) 
        { 
            RadNumericTextBox rdtxtbx = (RadNumericTextBox)RadToolBar1.Controls[0].FindControl("RadNumericTextBox1"); 
        } 


    Hope this helps..
    Shinu.

  3. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 09 May 2008 Link to this post

    Hello Joey,

    The FindControl method should work as expected. However, you first need to acces the button which holds the NumericTextBox and then use the FindControl method. Also, I noticed that you have used properties from the classic RadToolbar which have been changed or removed in the new ASP.NET AJAX RadToolbar. I suggest you refer to the topic on Migrating From RadToolBar ASP.NET to ASP.NET AJAX . Here is a modification of your code which will work as expected:

    <telerik:RadToolBar ID="DeploymentHistoryToolbar" runat="server" OnButtonClick="DeploymentHistoryToolbar_ButtonClick" > 
        <Items> 
            <telerik:RadToolBarButton  ToolTip="Refresh"   
                Text="Refresh" CommandName="Refresh"   
                AccessKey="r" /> 
            <telerik:RadToolBarButton Value="TemplateTextBox"  runat="server" ToolTip="Enter -1 to show all rows.">  
                <ItemTemplate> 
                    <class="toolBarText">Rows to show:</b> 
                    <telerik:RadNumericTextBox ID="txtResultCount" runat="server" InvalidStyle-BackColor="red" 
                        NumberFormat-DecimalDigits="0" Value="-1" Width="60px">  
                    </telerik:RadNumericTextBox> 
                </ItemTemplate> 
            </telerik:RadToolBarButton> 
        </Items> 
    </telerik:RadToolBar> 


    protected void DeploymentHistoryToolbar_ButtonClick(object sender, Telerik.Web.UI.RadToolBarEventArgs e)  
    {  
        RadNumericTextBox txb1 = (RadNumericTextBox)DeploymentHistoryToolbar.FindItemByValue("TemplateTextBox").FindControl("txtResultCount");  
        txb1.Value = -2;  




    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top