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

Menu ItemTemplate

3 Answers 202 Views
Menu
This is a migrated thread and some comments may be shown as answers.
satish
Top achievements
Rank 1
satish asked on 17 Mar 2009, 10:52 AM

<

telerik:RadMenuItem runat="server">

 

 

<ItemTemplate>

 

search:

 

<telerik:RadTextBox ID="txtQuickSearch" runat="server" Height="12px">

 

 

</telerik:RadTextBox>&nbsp;<asp:Button ID="btnQiuckSearch" runat="server" OnClick="btnQiuckSearch_Click"

 

 

Text="Go" BackColor="#FF8000" Height="22px" Font-Size="Small" BorderStyle="Double" /></ItemTemplate>

 

 

</telerik:RadMenuItem>


The above code .iam not able to access textbox and button  from the code behind.

Please give me the suggession.

Thanks
Satish.

 

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 17 Mar 2009, 11:45 AM
Hello Satish,

You can try out the following code to access the RadTextBox or Button from code behind:
cs:
 
 protected void RadMenu_PreRender(object sender, EventArgs e)  
    {  
        RadMenuItem menuItem = (RadMenuItem)RadMenu.Items[0]; // 0 indicates the menu item index 
        RadTextBox textBox = (RadTextBox)menuItem.FindControl("txtQuickSearch");  
        Button btn = (Button)menuItem.FindControl("btnQiuckSearch");  
    }  
 

Thanks
Princy.
0
Shinu
Top achievements
Rank 2
answered on 17 Mar 2009, 11:48 AM
 Hello Satish,

Try the following code snippet for getting reference to the controls placed in template of RadMenuItem. Here, I tried to find the RadMenuItem based on the value and access the controls in the template field.

CS:
protected void Button1_Click(object sender, EventArgs e)  
{  
    RadTextBox textBox = (RadTextBox)RadMenu1.FindItemByValue("Temp").FindControl("txtQuickSearch"); //Getting RadTextBox  
    Button tempButton = (Button)RadMenu1.FindItemByValue("Temp").FindControl("btnQiuckSearch"); // Getting reference to button  
}  

Make sure that you set the value for RadMenuItem.
ASPX:
<telerik:RadMenuItem runat="server" Value="Temp">  
    <ItemTemplate>  
    search:  
    <telerik:RadTextBox ID="txtQuickSearch" runat="server" Height="12px" Text="Hi">  
    </telerik:RadTextBox>&nbsp;  
    <asp:Button ID="btnQiuckSearch" runat="server"  
    Text="Go" BackColor="#FF8000" Height="22px" Font-Size="Small" BorderStyle="Double" />  
    </ItemTemplate>  
</telerik:RadMenuItem>  
Thanks,
Shinu.


0
satish
Top achievements
Rank 1
answered on 17 Mar 2009, 12:43 PM
Hi Shinu,

Thanks a lot.But i dont understand why you people made this much of complication to access the server side control from the Menu itemtemplate..

Thanks once agian..
Satish.
Tags
Menu
Asked by
satish
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
satish
Top achievements
Rank 1
Share this question
or