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

[Solved] ItemTemplate and findControl() returning null client-side

3 Answers 300 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Eve
Top achievements
Rank 1
Eve asked on 09 Sep 2009, 02:16 PM

Hello,

I am having trouble accessing controls in a RadMenu ItemTemplate in javascript.

I've used the code snippet supplied in the RadMenu documentation.  findItemByValue works, but calling findControl on that item to get to a control returns null.

Stepping into telerik's javascript, I can see that it does find a matching control id, but then returns null from the $find on that id.

Here is basically what I have:

<telerik:RadContextMenu ID="SearchContextMenu" runat="server">
            <Items>
                <telerik:RadMenuItem Value="FilterCustom">
                    <ItemTemplate>
                        <asp:TextBox ID="ContextMenuFilterTextBox" runat="server"></asp:TextBox>
                    </ItemTemplate>
                </telerik:RadMenuItem>
            </Items>
        </telerik:RadContextMenu>

And my related script:

         function RowContextMenu(sender, eventArgs) {
                var menu = $find("<%=SearchContextMenu.ClientID %>");

                //preload the filter textbox from the current cell
                var menuItem = menu.findItemByValue("FilterCustom");
                var textBox = menuItem.findControl("ContextMenuFilterTextBox");
                textBox.value = evt.target.innerHTML;
            }

Unfortunately, textBox is always null.

Can you reproduce this problem?

Thank you,
Eve


3 Answers, 1 is accepted

Sort by
0
Eve
Top achievements
Rank 1
answered on 09 Sep 2009, 02:20 PM
Whoops, forgot the script line:

var evt = eventArgs.get_domEvent();
0
Accepted
Veselin Vasilev
Telerik team
answered on 09 Sep 2009, 02:31 PM
Hello Eve,

the standard asp:TextBox does not have a client object which can be found with $find (or findControl) method.
You can use the findElement method of the $telerik client library like this:

 function RowContextMenu(sender, eventArgs) { 
                var menu = $find("<%=SearchContextMenu.ClientID %>"); 
 
                //preload the filter textbox from the current cell 
                var menuItem = menu.findItemByValue("FilterCustom"); 
                var textBox = $telerik.findElement(menuItem.get_element(), "ContextMenuFilterTextBox"); 
                textBox.value = evt.target.innerHTML
            } 

I hope this helps.

All the best,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Eve
Top achievements
Rank 1
answered on 09 Sep 2009, 02:37 PM
PERFECT!  Everything works now.  Thank you, Veselin!
Tags
Menu
Asked by
Eve
Top achievements
Rank 1
Answers by
Eve
Top achievements
Rank 1
Veselin Vasilev
Telerik team
Share this question
or