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

Treeview context menu click client and server side code both getting executed simultaneously

2 Answers 166 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Manas
Top achievements
Rank 1
Manas asked on 07 May 2012, 12:40 PM
Hi I have a RadTreeView where I have implemented a context menu on the nodes.

<telerik:RadTreeView ID="RadTreeView1" runat="server" OnContextMenuItemClick="RadTreeView1_ContextMenuItemClick" OnClientContextMenuItemClicking="onClientContextMenuItemClicking">               
             <ContextMenus>
                    <telerik:RadTreeViewContextMenu ID="ctxMenuAddK1" runat="server">
                        <Items>
                            <telerik:RadMenuItem Value="addNodeK1" Text="Add New K1 Node">
                            </telerik:RadMenuItem>                                            
                        </Items>
                     </telerik:RadTreeViewContextMenu>
            </ContextMenus>                       
</telerik:RadTreeView>


when user clicks the menu item, the client side event fires and a modal popup is displayed to the user. the modal popup has 2 text boxes, when user enters value in those text boxes and submits the popup, the text box values are concatenated and sent back to the calling page, where this value id captured in a hidden field.

case "addNodeK1":
var windowResult = window.showModalDialog("Controls\\newNodeK1.htm", "Enter Value", "dialogHeight: 300px; dialogWidth: 400px;");
document.getElementById('<%=HiddenField1.ClientID %>').value = windowResult;
break;

now the control goes to the server side context menu click event. here I am picking up the value from the hidden field, and do my tasks.

protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
{           
switch (e.MenuItem.Value)
{
case "addNodeK1": 
// get node name and node value from the hidden field.
string nameValue = HiddenField1.Value;
}
}

This works fine. the modal popup holds the execution until a value is submitted by the user. but the issue comes when I try to use radWindow instead of the modal popup.

I have added a radWindowManager and one child radWindow inside it. 

<telerik:RadWindowManager ID="RadWindowManager1" ShowContentDuringLoad="false" VisibleStatusbar="false"
        ReloadOnShow="true" runat="server" Skin="Sunset" EnableShadow="true">
        <Windows>
            <telerik:RadWindow ID="RadWindow1" runat="server" Behaviors="Close" OnClientClose="OnClientClose"
                NavigateUrl="Controls\\newNodeK1.htm">
            </telerik:RadWindow>           
        </Windows>
</telerik:RadWindowManager>

and I am trying to invoke the radwindow in the context menu clicked on the client.

var oWnd = radopen("Controls\\newNodeK1.htm", "RadWindow1");

The problem is that unlike the modal popup, it does not hold the execution. the RadWindow appears but the server side code executes simultaneously, and since the hidden field ie empty, my code does not work. what could be the solution of this problem? 

2 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 09 May 2012, 11:34 AM
Hi Manas,

The RadWindow is pure JavaScript and thus it cannot block the execution thread like the built-in browser dialogs can. The way to handle this is to use JavaScript and return the values from the RadWindow in its OnClientClose event as shown in this demo and this help article. This is the place where you would need to initiate a postback or ajax request (e.g. the ajaxRequestWithTarget() method of the RadAjaxManager) to  get the values to the server and perform your logic. You could use another hidden field to store the menu item that was clicked and prevent the default postback of the menu when the certain item (add K1 node) is clicked (via the set_cancel() method of the event arguments object the OnClientContextMenuItemClicking provides).  

 

Kind regards,
Marin
the Telerik team
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 their blog feed now.
0
Bhavya
Top achievements
Rank 1
answered on 22 Dec 2015, 06:12 AM

Hi,

Greetings!

Please help me out from my problem, it may be small but i cant make it out.

I am using a RadTreeView. its working fine but my requirment is i want to add some condition in between nodes of treeview. so that i have to display nodes based on that if condition.

 Thanks in advance. :)

Tags
TreeView
Asked by
Manas
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Bhavya
Top achievements
Rank 1
Share this question
or