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

Context Menu Not Displaying

11 Answers 149 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 17 Jul 2008, 03:31 PM
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.

11 Answers, 1 is accepted

Sort by
0
Erjan Gavalji
Telerik team
answered on 18 Jul 2008, 08:03 AM
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
0
Alex
Top achievements
Rank 1
answered on 18 Jul 2008, 03:06 PM
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
0
Erjan Gavalji
Telerik team
answered on 21 Jul 2008, 07:23 AM
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
0
Alex
Top achievements
Rank 1
answered on 21 Jul 2008, 02:18 PM
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

0
Atanas Korchev
Telerik team
answered on 21 Jul 2008, 02:32 PM
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
0
Alex
Top achievements
Rank 1
answered on 21 Jul 2008, 06:08 PM
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
0
Atanas Korchev
Telerik team
answered on 22 Jul 2008, 06:50 AM
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
0
Alex
Top achievements
Rank 1
answered on 22 Jul 2008, 01:40 PM
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);

0
Atanas Korchev
Telerik team
answered on 22 Jul 2008, 02:34 PM
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
0
Alex
Top achievements
Rank 1
answered on 22 Jul 2008, 03:02 PM
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 
0
Atanas Korchev
Telerik team
answered on 23 Jul 2008, 07:44 AM
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
Tags
Menu
Asked by
Alex
Top achievements
Rank 1
Answers by
Erjan Gavalji
Telerik team
Alex
Top achievements
Rank 1
Atanas Korchev
Telerik team
Share this question
or