Determine size of ContextMenu before showing???

4 posts, 0 answers
  1. Kevin
    Kevin avatar
    28 posts
    Member since:
    Feb 2009

    Posted 24 Jun 2010 Link to this post

    I'm trying to manually position my context menu, but need some method of finding it's rendered size prior to it actually being shown.

    Is this possible?

    I have a handle to the object with:

    var contextMenu = $find("<%= RadContextMenu1.ClientID %>");

    is there some property or method to get its height/width?



  2. Yana
    Admin
    Yana avatar
    5030 posts

    Posted 25 Jun 2010 Link to this post

    Hi Kevin,

    I'm afraid that you cannot get the size of the menu before it's shown - its width and height are 0.  You can use OnClientShown event and recalculate its position.

    Kind regards,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  3. Kevin
    Kevin avatar
    28 posts
    Member since:
    Feb 2009

    Posted 25 Jun 2010 Link to this post

    OK, cool... I can work with that... but how do I get the dimensions of the popup in this OnClientShown method?
  4. Yana
    Admin
    Yana avatar
    5030 posts

    Posted 28 Jun 2010 Link to this post

    Hello Kevin,

    You can use the following approach:

    <telerik:RadContextMenu ID="RadContextMenu1" runat="server" OnClientShown="clientShown" >       
        <Targets>
            <telerik:ContextMenuDocumentTarget />
        </Targets>
        <Items>
            <telerik:RadMenuItem Text="item 1" />
            <telerik:RadMenuItem Text="item 2" />
            <telerik:RadMenuItem Text="item 3" />
        </Items>
    </telerik:RadContextMenu>

    and the javascript function:

    <script type="text/javascript">
        function clientShown(sender, args) {
            var menuElement = sender.get_childListElement().parentNode;
            var width = menuElement.clientWidth;
            var height = menuElement.clientHeight;        
        }
    </script>

    All the best,
    Yana
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top