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

Getting and setting width client side

1 Answer 130 Views
Menu
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 19 Nov 2012, 05:31 PM
Hi,

I have a RadMenu context menu on my page. Items are added to it and removed from it client side. The problem is the items are not the same width. Some items can be very long in which case they extend past the right boundary of the context menu. Shorter items don't extend to the width of the context menu.

I thought I could use the ClientShowing method to loop through the items currently in the menu, determine the width of the longest one, then set the width of all the other items to this value. However I can't get the width of any of the items in the menu. The width and offsetwidth properties of each item (and it's linkelement, text element etc) are always 0.

How do I get the actual value of these?

Thanks,

Matt

1 Answer, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 22 Nov 2012, 01:50 PM
Hi Matt,

Using the code below you can easily set height and width to the RadContextMenu:
<telerik:RadContextMenu ID="RadContextMenu1" EnableRootItemScroll="true" EnableScreenBoundaryDetection="true"
                OnClientShown="OnClientItemOpening" EnableAutoScroll="true" runat="server">
                <DefaultGroupSettings Height="200px" />
             ....
                <Items>
                    <telerik:RadMenuItem Text="Item1"></telerik:RadMenuItem>
                </Items>
            </telerik:RadContextMenu>

javascript:
function OnClientItemOpening(sender, args) {
                   var scrollWrapElement = sender._getScrollWrapElement();
                   scrollWrapElement.style.height = "100px";
                   scrollWrapElement.style.width = "500px";
               }

All the best,
Kate
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Menu
Asked by
John
Top achievements
Rank 1
Answers by
Kate
Telerik team
Share this question
or