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("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.
rema10Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

masterpassCommented:
When you are creating the childnodes add this

childnode.SelectAction=TreeNodeSelectAction.SelectExpand;
0
rema10Author Commented:
Thanks for respdoning masterpass. I have that in my code already.   But, that didn't help.  

0
xav056Commented:
create your tree in  the paqe _init event
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

masterpassCommented:
see this link

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

just read the second post ... I hope that is your problem
0
rema10Author Commented:
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
rema10Author Commented:
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
xav056Commented:
try to put your code in the page_init and remove the !isposback condition
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rema10Author Commented:
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
xav056Commented:
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
rema10Author Commented:
Thanks Sagir for the follow-up comment.  This helps me to understand the 'why' and will help me in my future applications.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Applications

From novice to tech pro — start learning today.