Context Menu Not Displaying

12 posts, 0 answers
  1. Alex
    Alex avatar
    10 posts
    Member since:
    Jul 2008

    Posted 17 Jul 2008 Link to this post

    Hi I am new to using these Rad Controls and I wanted to create a simple context menu in a webpart which I have. This is the code which I have written for the menu but when I try to right click on the button the menu does not come up. Can anybody please help me?
    Thank You in advance.

    Alex

     

     //testButton is the button that needs to be right clicked for the menu to pop up

    testButton = new LinkButton();

    testButton.ID = "test_menu";

    testButton.Text = "Test";

                

    menu = new RadContextMenu();

    menu.ID = "RadContextMenu1";

    menu.Skin = "Vista";

     

    RadMenuItem item1 = new RadMenuItem();

    item1.Text = "Hello";

    item1.Value = "1";

    menu.Items.Add(item1);

     

    ContextMenuControlTarget aaa=new ContextMenuControlTarget();

    aaa.ControlID = "test_menu";

     menu.Targets.Add(aaa);

    Controls.Add(menu);

    Controls.Add(testButton);


    I also have a script manager and RadAjaxPanel in the method OnInit()



    I then render the testButton in the RenderContents() method.
    I can see the button but it does not do anything.

  2. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 18 Jul 2008 Link to this post

    Hi Alex,

    I'm afraid I'm missing a point here. Why is the need to render the testButton in the RenderContents method?

    The problem most probably happens, because the RadContextMenu cannot identify the client-side object, which the ControlTarget represents. You can try adding a ContextMenuElementTarget instead, which ElementID will point to the ClientID of the button.

    Regards,
    Erjan Gavalji
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. Alex
    Alex avatar
    10 posts
    Member since:
    Jul 2008

    Posted 18 Jul 2008 Link to this post

    The reason why I am rendering the testButton is because it will not display on the page otherwise.

    I have tried using ContextMenuElementTarget but I am still having the same problem. Could the problem be that the right click event is not being intercepted properly? I forgot to mension in the previous post that I am doing this in Sharepint 2007 SP1 Can this be caused by Sharepoint?

    Thanks

    Alex
  4. Erjan Gavalji
    Admin
    Erjan Gavalji avatar
    1455 posts

    Posted 21 Jul 2008 Link to this post

    Hi Alex,

    No, I don't think this is the problem.

    Here is a suggestion: Run the page, view its source and check the id attribute of the button you've added. Then, check the $create statement of the RadContextMenu in the HTML source. It should contain that id under the targets definition.

    Let me know if these match.

    Looking forward to your reply,
    Erjan Gavalji
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  5. Alex
    Alex avatar
    10 posts
    Member since:
    Jul 2008

    Posted 21 Jul 2008 Link to this post

    Hi Erjan,

    I have checked the ID's and they don't match. The ID of the button is:

    id="ctl00_m_g_f4b22f64_f952_4c7c_8c91_2b585fb65b7d_test_button

    and the ID in the $create statement of the RadContextMenu under the targets is:

     "targets":[{"id":"test_button","type":1}]}, null, null, $get("ctl00_m_g_f4b22f64_f952_4c7c_8c91_2b585fb65b7d_RadContextMenu1"));


    Alex

  6. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 21 Jul 2008 Link to this post

    Hello Alex,

    As suggested earlier you should use the ClientID property of your button which would return "tl00_m_g_f4b22f64_f952_4c7c_8c91_2b585fb65b7d_test_button". You could set it from codebehind to avoid hardcoding.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  7. Alex
    Alex avatar
    10 posts
    Member since:
    Jul 2008

    Posted 21 Jul 2008 Link to this post

    Hi,

    I have tried doing that but the ID's are still the same as before. I set the ContextMenuElementTarger ElementID to be ClientID of my button is that correct?

    Thanks,
    Alex
  8. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 22 Jul 2008 Link to this post

    Hello Alex,

    Yes. Also make sure that the button is added to the controls collection in order to have valid ClientID. If you use the ClientID prior to adding the button in the controls collection you would end up with the ID value.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  9. Alex
    Alex avatar
    10 posts
    Member since:
    Jul 2008

    Posted 22 Jul 2008 Link to this post

    Hi Albert,

    Thanks for the advice. I now have the ID's the same, but the menu still does not show when I right click the button. This is the updated version of the code. Am I still adding something in the wrong order?

    Thanks,
    Alex


    testButton =

    new LinkButton();

    testButton.Text =

    "Test";

    Controls.Add(testButton);

    menu =

    new RadContextMenu();

    menu.Skin =

    "Vista";

     
    RadMenuItem
    item = new RadMenuItem();

    item.Text =

    "Hello";

    item.Value =

    "1";

    menu.Items.Add(item);


    ContextMenuElementTarget
    aaa = new ContextMenuElementTarget();

    aaa.ElementID = testButton.ClientID;

    menu.Targets.Add(aaa);

    Controls.Add(menu);

  10. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 22 Jul 2008 Link to this post

    Hi Alex,

    Do you see any JavaScript errors when you load the page? This may be preventing RadMenu from showing. You can try adding a regular RadMenu to see it works ok.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  11. Alex
    Alex avatar
    10 posts
    Member since:
    Jul 2008

    Posted 22 Jul 2008 Link to this post

    Hi Albert,

    Yes there is a javascript error when I hover the mouse over the button. It is as follows:
    javascript:_dpPostBack('ctl00$m$g_f4b22f64_f952_4c7c_8c91_2b585fb65b7d$ctl00',")
     
    which appears to be the clientID of the button.

    the actual clientID is:  id":"ctl00_m_g_f4b22f64_f952_4c7c_8c91_2b585fb65b7d_ctl00"

    I added a regular RadMenu and it appears to work fine


    Thanks,
    Alex 
  12. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 23 Jul 2008 Link to this post

    Hi Alex,

    This is actually expected. This is the UniqueID of the button whilst the other is its ClientID.
    Unfortunately I am out of any other ideas why the context menu might not work in your case. I suggest you send us your webpart by opening a support ticket.

    Regards,
    Albert
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
Back to Top