rema10
asked on
My selectednodechanged event handler is not firing(ASP.NET, c#)
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("Pan el1").Cont rols.Add(t vtest);
Panel1.Controls.Add(tvtest );
tvtest.SelectedNodeChanged += new EventHandler(tvtest_Select edNodeChan ged);
}
void tvtest_SelectedNodeChanged (object sender, EventArgs e)
{
.....
some functions written here to do calculations etc...
..
}
Thanks for your help and time.
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("Pan
Panel1.Controls.Add(tvtest
tvtest.SelectedNodeChanged
}
void tvtest_SelectedNodeChanged
{
.....
some functions written here to do calculations etc...
..
}
Thanks for your help and time.
ASKER
Thanks for respdoning masterpass. I have that in my code already. But, that didn't help.
create your tree in the paqe _init event
see this link
http://forums.asp.net/p/1458201/3343969.aspx
just read the second post ... I hope that is your problem
http://forums.asp.net/p/1458201/3343969.aspx
just read the second post ... I hope that is your problem
ASKER
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?
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?
ASKER
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.
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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
Hope this will give you a simple methodology to follow
ASKER
Thanks Sagir for the follow-up comment. This helps me to understand the 'why' and will help me in my future applications.
childnode.SelectAction=Tre