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.
11 Answers, 1 is accepted
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
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
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
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
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
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
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
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);
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
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
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