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

TreeView with ModalPopup and buttons

3 Answers 204 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Henrik
Top achievements
Rank 1
Henrik asked on 02 Aug 2010, 03:01 PM

Hi,

I want my TreeView to remove a marked post when I've confirmed it from a button located in a modal popup.

Scenario:

1. TreeView is populated from DB.

2. Right click on some item.

3. Choose delete.

4. Modal popup appears asking if you're sure you want to delete the selected node.

5. If no, just close the popup. If yes, delete it from DB and refresh tree.

The problem is that it has to rerender the tree to show the changes. Is it possible to use the .Remove() function from a asp:button? If so, can I also use the add and rename functions?

Code for TreeView:

01.Protected Sub tree_ContextMenuItemClick(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadTreeViewContextMenuEventArgs) Handles tree.ContextMenuItemClick
02.    Dim node As RadTreeNode = e.Node
03.    Dim item As RadMenuItem = e.MenuItem
04.    Dim menu As RadMenu = item.Menu
05.    Dim value As String = item.Value
06. 
07.    Dim r As New Regex("\d*:"
08.    Dim strName As String = node.Text
09.    Select Case value
10.        Case "3" 'delete
11.            hdfNode.Value = node.Value
12.            If (r.IsMatch(strName)) Then
13.                lblConfirmDelete.Text = strName.Substring(strName.IndexOf(": ") + 2).Replace("*", "")
14.            Else
15.                lblConfirmDelete.Text = strName.Replace("*", "")
16.            End If
17.            mpeNodeDelete.Show()
18.            Exit Select
19.    End Select
20.End Sub

Code for button:

1.Protected Sub btnNodeDelete_ok_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNodeDelete_ok.Click
2.    Try
3.    wrkTree.DeleteNode(hdfNode.Value.ToString())
4.    Catch ex As Exception
5.        lblMess.Text = ErrorHandler.ExceptionTranslation(ex)
6.    End Try
7.    setuptree()
8.End Sub

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 05 Aug 2010, 04:10 PM
Hi Henrik,

Please check this online demo - it shows how to add and remove nodes on the server.

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
0
Henrik
Top achievements
Rank 1
answered on 06 Aug 2010, 09:11 AM

I'm sorry, but it doesn't work. I tried:

1.Protected Sub btnNodeDelete_ok_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNodeDelete_ok.Click
2.    Try
3.        tree.SelectedNode.Remove()
4.    Catch ex As Exception
5.        lblMess.Text = ErrorHandler.ExceptionTranslation(ex)
6.    End Try
7.End Sub

But all I get is this:

System.NullReferenceException: Object reference not set to an instance of an object.

0
Yana
Telerik team
answered on 10 Aug 2010, 03:13 PM
Hello Henrik,

I guess that the problem is that tree.SelectedNode is null. You can work-around it like this:

1. subscribe to OnClientContextMenuShown event of the treeview.
2. set the selected state of the node in the event handler:

<script type="text/javascript">
    function menuShown(sender, args) {
        sender.trackChanges();
        args.get_node().set_selected(true);
        sender.commitChanges();
    }
</script>

in this way tree.SelectedNode will return the correct node.

Please try it and let us know whether it helps.

All the best,
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
Tags
TreeView
Asked by
Henrik
Top achievements
Rank 1
Answers by
Yana
Telerik team
Henrik
Top achievements
Rank 1
Share this question
or