Display RadTreeViewContextMenu after postback

4 posts, 1 answers
  1. Gene
    Gene avatar
    64 posts
    Member since:
    Dec 2007

    Posted 17 Aug 2009 Link to this post

    I have a RadTreeViewContextMenu on a RadTree that contains an Item Template with a textbox. button, and customvalidator.  On Postback, I need to display the RadTreeViewContextMenu if validation fails.  I'm at a loss on how to do this.  Any ideas?

    Thanks in advance,
    Gene.
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 18 Aug 2009 Link to this post

    Hi Gene,

    Here is how you can do this: if the validation fails register a javascript by using RegisterStartupScript method of the ScriptManager class. That javascript will do the following: finds the context menu and shows it using the showAt client-side method of the menu.

    Here is a sample C# code:

    StringBuilder script = new StringBuilder(); 
    script.Append("Sys.Application.add_load(function(){"); 
    script.Append("var menu = $find('" + RadTreeView1.ContextMenus[0].ClientID + "');"); 
    script.Append("menu.showAt(100, 100);"); 
    script.Append("});"); 
     
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "openContext", script.ToString(), true); 

    I hope this will get you started.

    Greetings,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Gene
    Gene avatar
    64 posts
    Member since:
    Dec 2007

    Posted 18 Aug 2009 Link to this post

    Thanks for your reply Veselin!

    Works great! Next question: How do I dynamically get the position of the contextmenu?

    Thanks again,
    Gene.
  5. Answer
    Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 21 Aug 2009 Link to this post

    Hi Gene,

    Supposing you want to show the context menu over the selected node here is the amended code:

    StringBuilder script = new StringBuilder();  
    script.Append("Sys.Application.add_load(function(){");  
    script.Append("var menu = $find('" + RadTreeView1.ContextMenus[0].ClientID + "');");  
    script.Append("var tree = $find('" + RadTreeView1.ClientID + "');"); 
    script.Append("var node = tree.get_selectedNode(); if (node) {"); 
    script.Append("var nodeLocation = $telerik.getLocation(node.get_textElement());"); 
    script.Append("menu.showAt(nodeLocation.x + 20, nodeLocation.y + 10);}");  
    script.Append("});");  
      
    ScriptManager.RegisterStartupScript(Page, Page.GetType(), "openContext", script.ToString(), true);  


    Sincerely yours,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top