1

I have a treeview asp.net control. And I have the following SelectedNodeChanged Event ofr Treeview1.

Private Sub TreeView1_SelectedNodeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TreeView1.SelectedNodeChanged           
        Try    
            Dim type As Boolean = False    
            Dim nodetext As String = TreeView1.SelectedNode.Value    
            Dim depth As Integer = TreeView1.SelectedNode.Depth    
            If nodetext = "Root" Then    
                btnCreateComp.Visible = True                   
                btnCreateComp.Text = "Create Company"    
                btnCreateUser.Visible = False    
            Else    
                type = getNodeType(nodetext)    
                'if it is true its USER
                'if false it is COMPANY

                If type = True Then                           
                    btnCreateComp.Visible = False                      
                    btnCreateUser.Visible = True
                    btnCreateUser.Text = "Edit User"
                    btnCreateUser.PostBackUrl = "~/Account/User.aspx"    
                Else                    
                    btnCreateComp.Visible = True
                    btnCreateComp.Text = "Edit Company"                      
                    btnCreateUser.Visible = True
                    btnCreateUser.Text = "Create User"    
                    btnCreateUser.PostBackUrl = "~/Account/User.aspx"    
                End If    
            End If    
        Catch ex As Exception    
        End Try    
    End Sub

When I click on a node, and if it is not "root", it makes 2 buttons visible, if I click the button btnCreateUser , it goes to a page "user.aspx", which is postbackurl for btnCreateUser.

This is fine. But when the next time a click a node other than "Root", it directly goes to the postbackurl page "User.aspx", even though I have not clicked on the Button btnCreateUser.

And this happens only once after the first time I have clicked "btnCreateUser".

Can anyone please help?

Iswanto San
  • 18,263
  • 13
  • 58
  • 79
shradha
  • 147
  • 2
  • 16
  • can anyone please help.:( – shradha Feb 22 '13 at 08:18
  • Check Post back condition on Page Load. Something Like `if (!Page.IsPostBack)` if postback you want to keep then you have to Rebind the data and set `TreeView1.SelectedNode.Value` – RajeshKdev Feb 22 '13 at 08:28
  • you should also post code of handler btnCreateUser_Click – jbl Feb 22 '13 at 08:31
  • there is no button click event code for btnCreateUser_Click – shradha Feb 22 '13 at 08:37
  • i have put the {If Not Page.IsPostBack Then PopulateTreeView() btnCreateComp.Visible = False btnCreateUser.Visible = False 'btnEditUser.Visible = False End If } – shradha Feb 22 '13 at 08:39
  • @shradha Still you are facing the same problem..? Try to debug line by line and see why.. its better to understand your problem. – RajeshKdev Feb 22 '13 at 09:53
  • @RJK I debugged complete process, after I click on a node, selectednodechanged function gets called and the next thing which gets hit is the "user.aspx" page load event. without even showing me the current page. – shradha Feb 22 '13 at 09:58
  • @shradha Check your name and ID of the Tree View properties using Firbug. Check for Html Tags also properly binding or not with starting and closing tags. I'm sure Something you are missing here it might be same id for tree view nodes or property retrieving, assigning values same. Check it out.. – RajeshKdev Feb 22 '13 at 10:05

0 Answers0