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

programmatically adding RadContextMenu

1 Answer 280 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
reza
Top achievements
Rank 1
reza asked on 06 Feb 2012, 07:00 PM
Hi
I wanna create a custom server control (from CompositeControl base) that has context menu by default
by something like this : 

       protected override void CreateChildControls()
        {
            base.CreateChildControls();
           
            Panel pnl = new Panel();
            pnl.ID = "pnl";
            pnl.Width = Unit.Pixel(100);
            pnl.Height = Unit.Pixel(100);
            pnl.BackColor = System.Drawing.Color.Black;
            this.Controls.Add(pnl);

            RadContextMenu cntMenu = new RadContextMenu();
            cntMenu.ID = "cntM";
            RadMenuItem mItem = new RadMenuItem("Delete");
            cntMenu.Items.Add(mItem);
            ContextMenuElementTarget target = new ContextMenuElementTarget();
            target.ElementID = pnl.ClientID;
            this.Controls.Add(cntMenu);


        }

But it does not work
Is it possible to add ContextMenu dynamically ?
Have I done something wrong ?

Thank you very much for your feedbacks



1 Answer, 1 is accepted

Sort by
0
reza
Top achievements
Rank 1
answered on 06 Feb 2012, 07:05 PM
I am so sorry
I had forgotten  to add this line

cntMenu.Targets.Add(target);

it's working perfectly
Thanks
Tags
General Discussions
Asked by
reza
Top achievements
Rank 1
Answers by
reza
Top achievements
Rank 1
Share this question
or