Close menu item on button click in template

7 posts, 1 answers
  1. Sergey Sugak
    Sergey Sugak avatar
    5 posts
    Member since:
    Apr 2010

    Posted 18 May 2010 Link to this post

    Hello, guys.
    I have menu item with template. There are several controls. Among them button.
    How do I make this button to close menu item it's in and then process what is aasigned to it's server OnClick part?
    Now what I experience is menu item stays on util I move mouse out of the content of the template.

    With respect, Sergey.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 May 2010 Link to this post

    Hello,

    If you want to close the RadMenuItem, then you can simply use the 'close()' method of corresponding radmenuitem client object.

    In trhe case of achieving the same from code behind, you could invoke one client method from server using "ScriptManager.RegisterStartupScript" by passing the menuitem value. And in the client function access the menu item and use the close method to collapse the item.

    Thanks,
    Princy.
  3. Sergey Sugak
    Sergey Sugak avatar
    5 posts
    Member since:
    Apr 2010

    Posted 21 May 2010 Link to this post

    "you could invoke one client method from server using "ScriptManager.RegisterStartupScript" by passing the menuitem value"

    I'm not really javascript fan. So could you please give me a working code exapmle for this call?
    Thanks in advance,
    with respect, Sergey.
  4. Yana
    Admin
    Yana avatar
    5013 posts

    Posted 21 May 2010 Link to this post

    Hello Sergey,

    Please check this blog post for more information about executing javascript from code-behind.

    Best wishes,
    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.
  5. Sergey Sugak
    Sergey Sugak avatar
    5 posts
    Member since:
    Apr 2010

    Posted 21 May 2010 Link to this post

    Hello again.
    I didn't mean I don't know how to call this or those javascript function from codebihind. I meant that I would really appreciate if someone could show me the exact call of "the 'close()' method of corresponding radmenuitem client object" with "passing the menuitem value".

    With respect, Sergey.
  6. Answer
    Yana
    Admin
    Yana avatar
    5013 posts

    Posted 26 May 2010 Link to this post

    Hi Sergey Sugak,

    Here is a sample which shows how to use close() method:

    <telerik:RadMenu ID="RadMenu1" runat="server">
        <Items>
            <telerik:RadMenuItem Text="root item">
                <Items>
                    <telerik:RadMenuItem Value="tempButton">
                        <ItemTemplate>
                            <asp:Button ID="button1" Text="click" OnClientClick='closeItem("tempButton")'  runat="server" />
                        </ItemTemplate>
                    </telerik:RadMenuItem>
                </Items>
            </telerik:RadMenuItem>
        </Items>
    </telerik:RadMenu>

    and the closeItem function:

    <script type="text/javascript">
        function closeItem(val) {
            alert(1);
            var menu = $find("<%=RadMenu1.ClientID %>");
            menu.findItemByValue(val).get_parent().close();
            return false;
        }
    </script>


    Best 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.
  7. Sergey Sugak
    Sergey Sugak avatar
    5 posts
    Member since:
    Apr 2010

    Posted 27 May 2010 Link to this post

    Thanks, Yana.
    Now it's all clear.

    With respect, Sergey.
Back to Top