This is a migrated thread and some comments may be shown as answers.

FindControl doesn't work

2 Answers 181 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Joey
Top achievements
Rank 1
Joey asked on 09 May 2008, 03:41 AM

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 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 09 May 2008, 11:02 AM
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.

0
Peter
Telerik team
answered on 09 May 2008, 01:11 PM
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
Tags
Menu
Asked by
Joey
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Peter
Telerik team
Share this question
or