?
Solved

My selectednodechanged event handler is not firing(ASP.NET, c#)

Posted on 2010-03-23
10
Medium Priority
?
1,883 Views
Last Modified: 2012-05-09
Hello,

First, I am a newbie...

I have created a treeview programmatically.  The tree shows up fine in the page.  But when I click on a node the tree just disappears from the page and the 'selectednodechanged' event is not fired.

eg: In page_load:
{
if (!IsPostBack)
{
buildtree tree1 = new buildtree();
tvtest = tree1.create_tree();
tvtest.ShowExpandCollapse = true;
tvtest.ShowLines = true;
tvtest.DataBind();
this.Form.FindControl("Panel1").Controls.Add(tvtest);
Panel1.Controls.Add(tvtest);
tvtest.SelectedNodeChanged += new EventHandler(tvtest_SelectedNodeChanged);
        }

void tvtest_SelectedNodeChanged(object sender, EventArgs e)
{

.....
some functions written here to do calculations etc...
..
}


Thanks for your help and time.
0
Comment
Question by:rema10
  • 5
  • 3
  • 2
10 Comments
 
LVL 21

Expert Comment

by:masterpass
ID: 28382468
When you are creating the childnodes add this

childnode.SelectAction=TreeNodeSelectAction.SelectExpand;
0
 

Author Comment

by:rema10
ID: 28382813
Thanks for respdoning masterpass. I have that in my code already.   But, that didn't help.  

0
 
LVL 9

Expert Comment

by:xav056
ID: 28398623
create your tree in  the paqe _init event
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
LVL 21

Expert Comment

by:masterpass
ID: 28416303
see this link

http://forums.asp.net/p/1458201/3343969.aspx

just read the second post ... I hope that is your problem
0
 

Author Comment

by:rema10
ID: 28450020
Thanks both of you.  

I tried both the solutions and I tried some of my own too - but didn't work.
1.  creating inthe page_init event: didn't help.
2.  setting the navigateurl property to null: didn't help.

Just so you know:
the event-function is called if I use the 'TreeNodeExpanded' event.

So, is there something that I should be adding/writing to know that the node is being selected/clicked?  

0
 

Author Comment

by:rema10
ID: 28452027
ADDITONALLY..

Another FYI:  Here is also something that I noticed.

When I click on a node, there is a postback event.  After the postback event, I check the 'watch window' for the contents of the tree and it shows as null.

So, pls let me know where I am going wrong..

Thanks.
0
 
LVL 9

Accepted Solution

by:
xav056 earned 2000 total points
ID: 28453932
try to put your code in the page_init and remove the !isposback condition
0
 

Author Closing Comment

by:rema10
ID: 31706625
Thanks much.  That worked for me.

I am still trying to understand placing the server controls in the page_init vs the page_load event.  I was reading the msdn website on the page's life cycle.  But, if you have simple words that can explain why the tree should be created in the page_init event etc. please let me know.  

Again, thanks and appreciate your help and time.
0
 
LVL 9

Expert Comment

by:xav056
ID: 28606391
When dealing with dynamic controls, you have to make sure your controls arecreated in the page init, this is where the stateview would be loaded, it would be too late to load the view state in the page load event and thus if you are creating dynamic controls in the page load you will loose the state.
Hope this will give you a simple methodology to follow
0
 

Author Comment

by:rema10
ID: 28677112
Thanks Sagir for the follow-up comment.  This helps me to understand the 'why' and will help me in my future applications.
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using Quotation Marks in PHP This question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28217211.html) seems to come up a lot for developers who are new to PHP.  And it got me thinking, "How can we explain the rule…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question