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

Display RadTreeViewContextMenu after postback

3 Answers 42 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Gene
Top achievements
Rank 1
Gene asked on 17 Aug 2009, 04:43 PM
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.

3 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 18 Aug 2009, 09:39 AM
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.
0
Gene
Top achievements
Rank 1
answered on 18 Aug 2009, 04:22 PM
Thanks for your reply Veselin!

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

Thanks again,
Gene.
0
Accepted
Veselin Vasilev
Telerik team
answered on 21 Aug 2009, 02:32 PM
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.
Tags
TreeView
Asked by
Gene
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Gene
Top achievements
Rank 1
Share this question
or