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

Find Dynamic created RadMenu Item in GridView

3 Answers 125 Views
Menu
This is a migrated thread and some comments may be shown as answers.
johnson lim
Top achievements
Rank 1
johnson lim asked on 13 May 2010, 04:35 AM
Hi, I have a dynamic gridview in which i need to add the RadContextMenu to the gridview cell dynamically.
Every RadContextMenu may has one or two or more RadMenuItem added to it based on situation.

I am able to capture which RadContextMenu cause postback in the web pages  ( Request.Form("__EVENTTARGET") ) , however, i need to access to the text of the RadMenuItem then only i can decide whether some control need to be generated based on the RadMenuItem click in the Page load event.
The purpose of doing so is to avoid the the dynamic control item is generated once in pageload event where postback =true  and generated again on the RadMenuItemClick event.


Does anyone has idea on this?

3 Answers, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 19 May 2010, 07:42 AM
Hi Johnson,

If I understand correctly, you'd like to skip creating the dynamic control after postback, but still be able to figure out which menu item was clicked.

The RadMenu will send only the hierarchical index of the clicked item. If you look at the __EVENTARGUMENT field you'll see that it looks like this "0:2" (the third child of the first root item). This information might not be sufficient to figure out what this item is though.

You can store additional information about the clicked item in a hidden field and use it instead.

<form id="form1" runat="server">
<asp:ScriptManager ID="RadScriptManager1" runat="server">
</asp:ScriptManager>
 
<script type="text/javascript">
    function itemClicked(s, e) {
        var field = $get("<%= ClickedItemValue.ClientID %>");
        field.value = e.get_item().get_value();
    }
</script>
 
<script runat="server">
    protected void ClickedItemValue_ValueChanged(object sender, EventArgs e)
    {
        throw new Exception(ClickedItemValue.Value);
    }
 
    protected void RadMenu1_ItemClick(object sender, RadMenuEventArgs e)
    {
         
    }
</script>
 
<asp:HiddenField runat="server" ID="ClickedItemValue" OnValueChanged="ClickedItemValue_ValueChanged"/>
 
<telerik:RadMenu ID="RadMenu1" runat="server" OnClientItemClicked="itemClicked" OnItemClick="RadMenu1_ItemClick">
    <Items>
        <telerik:RadMenuItem Text="Sample Item" Value="3.14">
        </telerik:RadMenuItem>
    </Items>
</telerik:RadMenu>

I hope this helps.

Sincerely yours,
Tsvetomir Tsonev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Kyle
Top achievements
Rank 1
answered on 21 Aug 2014, 08:07 PM
I have run into the exact issue and have seen the format of the __EVENTARGUMENT as described. My question is.... if the information is not sufficient to figure out which item it is, why does it exist? It seems to me that there IS enough information, there's just no method to call like .FindItemByEventArgument(). There's probably a way to do it but I don't know enough about the internals of the RadMenu to write that method. Maybe Telerik could give us some insight? Thanks.
0
Dimitar
Telerik team
answered on 22 Aug 2014, 11:53 AM
Hi Kyle,

The information stored in the __EVENTARGUMENT  field contains the hierarchical index of the menu item which was clicked. If the items of the RadMenu are available on the sever, based on this hierarchical index the menu item which was clicked is referenced and then passed to the ItemClick event for instance.

The situation discussed in this forum post is a bit different, since the dynamically created items are not available on the server this hierarchical index won't be helpful, since there is no items collection to search in.

Regards,
Dimitar
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Menu
Asked by
johnson lim
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Kyle
Top achievements
Rank 1
Dimitar
Telerik team
Share this question
or