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

Click Contextmenu block (or Instead) the event

1 Answer 29 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Hon
Top achievements
Rank 1
Hon asked on 31 Jul 2013, 03:57 PM

Dear  experts , how  to handle  following

  after  click  on  the  Context menu  item  in  onClientContextMenuItemClicking (or OnClientContextMenuItemClicked)  event,  and  then  the  popup  div  layers (or aspx pages), and  gets  inside  the  text  of  TextBox1(TextBox1.Text:

 

1. when TextBox1.text  is  not  null (or is  not  empty  string ), return  true, and  execut  service RadTreeView1_ContextMenuItemClick  event  ;

2. when TextBox1.text is null (or empty string), returns  false, will  does not  execut  services RadTreeView1_ContextMenuItemClick  event.

 

Reference:

Client  code:

function onClientContextMenuItemClicking(sender, args) {

var menuItem = args.get_menuItem();

var treeNode = args.get_node();

menuItem.get_menu().hide();

switch (menuItem.get_value()) {

case "new":

var  result=  pseudocode(pop-up layer :  when  input  text  of  TextBox1 is not null or not  empty  string ): return true;  when TextBox1.text  is null  or empty  string  return  false.);

args.set_cancel(!result);  

break;

 

Description

1.  /*  When variable  result  return  false  and  did not  execut RadTreeView1_ContextMenuItemClick .   Key points: When the pop-up layers, how to block  the  program to continue execut */  

2. /* this (pseudocode) is  my problem , and  how can  I  write  the  code ? */

}


Services  code:

 

protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)

{

RadTreeNode clickedNode = e.Node;

switch (e.MenuItem.Value)

{

case "new":

if(! IsNullOrEmpty (textbox1.text))

clickedNode.Nodes.Add(textbox1.text);

}}

many  thanks!


1 Answer, 1 is accepted

Sort by
0
Hristo Valyavicharski
Telerik team
answered on 05 Aug 2013, 02:12 PM
Hi Hon,

Execution will stops and RadTreeView1_ContextMenuItemClick event will not fired if you cancel the client onClientContextMenuItemClicking event. Just be sure that pass true as argument: args.set_cancel(true);

For the the second issue you may try to replace your pseudo code with the following:
function onClientContextMenuItemClicking(sender, args) {
    var menuItem = args.get_menuItem();
    var treeNode = args.get_node();
    menuItem.get_menu().hide();
 
    //Get text value of TextBox1
    var text = $get('TextBox1').value;
    switch (menuItem.get_value()) {
 
        case "new":
            //Check if TextBox1 contains any text
            var result = isEmpty(text);
            //If TextBox1 is empty cancel the event and stops execution
            args.set_cancel(result);
            break;
    }
}
 
function isEmpty(value) {
    return (typeof value === "undefined" || value === null || value === "");
}


Regards,
Hristo Valyavicharski
Telerik
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 the blog feed now.
Tags
TreeView
Asked by
Hon
Top achievements
Rank 1
Answers by
Hristo Valyavicharski
Telerik team
Share this question
or