RadContextMenu on dynamically created image buttons

12 posts, 1 answers
  1. jgig
    jgig avatar
    61 posts
    Member since:
    Apr 2008

    Posted 09 Sep 2008 Link to this post


    I have an RadAjaxPanel that has a panel in it that I dynamically create Image buttons in for cached searches. This works fine. I want to add a context menu to each button so I can give the user a way to remove the cached search. So if left-click the button it will redirect them to open the seach. When they Right-click I want the context menu to appear. Not sure the best way to do this on the server and attach individually to dynamic buttons.

    Any samples show something like this?
  2. Yana
    Admin
    Yana avatar
    4841 posts

    Posted 10 Sep 2008 Link to this post

    Hello,

    I suggest you create the context menu in the aspx page like this:

    <telerik:RadContextMenu ID="contextMenu1" runat="server">  
        <Items> 
            <telerik:RadMenuItem Text="delete" /> 
        </Items> 
    </telerik:RadContextMenu> 

    and then when you create the image buttons, you can set them as targets of the menu:
     
    ImageButton btn = new ImageButton();  
    btn.Text = "btn text";  
    btn.ID = "btnID";  
    ContextMenuControlTarget target = new ContextMenuControlTarget();  
    target.ControlID = "btnID";  
    contextMenu1.Targets.Add(target); 

    Hope this helps.

    Greetings,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. jgig
    jgig avatar
    61 posts
    Member since:
    Apr 2008

    Posted 10 Sep 2008 Link to this post

    OK I did what you said but I never see the menu. Haven't used this control before and there isn't alot of content to read about it.

    How do I assign it to Right Click show the menu?
    Since I have '1 to many' ImageButtons I am assigning this to... can I add a whats the correct way to kick off a shared function to process the delete and to tell the buttons appart?

    Right now I am assigning this and this is unique:
    target.ControlID = string.Format("SearchButton{0}", sw.ID);
  4. jgig
    jgig avatar
    61 posts
    Member since:
    Apr 2008

    Posted 10 Sep 2008 Link to this post

    Oops, I do see the menu now. I have also wired up the ItemClick

    my next question is how from the ItemClick event on the server can I get which menu was clicked? I need to make it unique sot that I know which menu (target) fired off the event so I can perform a function.

    I am using the ContextMenuControlTarget like you suggested.

    thanks
  5. Yana
    Admin
    Yana avatar
    4841 posts

    Posted 12 Sep 2008 Link to this post

    Hello,

    You have to subscribe to OnClientShowing event of the context menu and set a custom attribute to the id of its target button. In this way in Atomics event handler you can get the target of the opened menu. I prepared a small demo project which shows this approach. Please download the attached file and give it a try.

    Kind regards,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. jgig
    jgig avatar
    61 posts
    Member since:
    Apr 2008

    Posted 12 Sep 2008 Link to this post

    thank you for the sample proj. I am going to try it asap. Another small issue is that I am putting buttons in my ajaxpanel. They no longer work. When I click them it just Updates the RadAjaxPanel and my event is lost. The UpdatePanel has a ChildrenasTriggers property...I can't find a similar property on the RadAjaxPanel. Anything special I need to do or set for this?
  7. Answer
    Yana
    Admin
    Yana avatar
    4841 posts

    Posted 15 Sep 2008 Link to this post

    Hello,

    In the project I attached in my previous post I use RadAjaxPanel and it works without a problem. Could you please check what is different in your case?

    If you still experience this issue, open a support ticket and send us your project so we can test it locally. Thanks

    Regards,
    Yana
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  8. jgig
    jgig avatar
    61 posts
    Member since:
    Apr 2008

    Posted 15 Oct 2008 Link to this post

    sorry for the late reply. This project helped me achieve the desired effect. Assigning dynamic attributes to the button and getting access to them through the javascript of the target element is just what I needed.
  9. jgig
    jgig avatar
    61 posts
    Member since:
    Apr 2008

    Posted 04 Dec 2008 Link to this post


    I updated to the latest version of Rad AJAX Controls "Telerik.Web.UI, Version=2008.3.1105.35". Now it doesnt work again (only works in IE) for FF and Safari

    it definately did before, the attributes are set in the HTML. but the MenuID and the MenuType from the attributes are NULL. Do I need to do this differently for the attributes?

    protected void rcmSubMenu_ItemClick(object sender, RadMenuEventArgs e) 
            { 
                string MenuID = rcmSubMenu.Items[0].Attributes["MenuID"]; 
                string MenuType = rcmSubMenu.Items[0].Attributes["MenuType"]; 
     
                if (MenuID != null && MenuType != null && MenuID != string.Empty && MenuType != string.Empty) 
                { 
                    if (MenuType == "Other")//ALL search windows - except PNR 
                    { 
                        SearchList.GetSearchList().Remove(int.Parse(MenuID)); 
                    } 
                    else//PNR  
                    { 
                        PNRList.Current.Remove(int.Parse(MenuID)); 
                    } 
                    LoadSubMenu();//Reload Sub Menu 
                } 
            } 

  10. jgig
    jgig avatar
    61 posts
    Member since:
    Apr 2008

    Posted 04 Dec 2008 Link to this post

    OK I fixed my problem (I dont think it was tested in the other browsers after all)

    the ZIP file had javascript code to get the id and I assumed it was ok to get custom attributes like that. Worked in IE so I think I just didnt even notice it. Oops

    Changed
    attributes.setAttribute("MenuType", targetElement.MenuType);
    to
    attributes.setAttribute("MenuType", targetElement.getAttribute("MenuType"));

    actually surprised IE worked like that

  11. Stone Heart
    Stone Heart avatar
    1 posts
    Member since:
    Jan 2010

    Posted 23 Mar 2010 Link to this post

    Hi.

    How to add target element in client side ?

    thanks.
  12. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 26 Mar 2010 Link to this post

    Hi Stone Heart,

    You can use the addTargetElement method of the RadContextMenu client object.

    Kind regards,
    Veskoni
    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.
Back to Top