I have a master page with a TreeView, which is filled from a SiteMapDataSource. I have added an UpdatePanel, inside which i have placed a ContentPlaceholder. I have created an AsyncPostBackTrigger which looks like this:
<asp:AsyncPostBackTrigger ControlID="NavigationTreeView" EventName="SelectedNodeChanged" /
The problem is that the postback is still executed everytime i click on a node,making the UpdatePanel useless.
I have tried disabling treeview postbacks, by changing the Node.Text to <span onclick='return false;'>" + tempNodeLabel + "</span>";
But in this case, the SelectedNodeChanged event does not happen.
What i want in a nutshell is to make the content of a page update without fully reloading the page,while using TreeView as a trigger.
I have heard that TreeView doesn't support partial page updates.
Can anyone suggest how can i make treeview support it or how to disable postbacks while leaving SelectedNodeChanged event,or how can i achieve the desired result in any other manner?
Can anyone help please?
I'm using the treeview triggering/updating other updatepanels this way:
1. The treeview is in an updatepanel and there is the same asyncpostbacktrigger as your inthat updatepanel.
2. I handle theSelectedNodeChanged event in code behind, and update the necessary updatepanels with theupdate( ) method.
Step 1. is not supported officially.
The treeview "may works" inside the up, but very buggy and has strange/unexpected behavior, prepare for some surprise...
Thank you for an advice
But i'm a bit confused. The SelectedNodeChanged event happens only if the navigateurl property of a node is blank. In this case, how do i pass the URL which has to be shown to the UpdatePanel?
Ok, i've placed the TreeView inside an UpdatePanel and postbacks don't happen as long as the navigateurl property is blank. The only thing i don't get is how to let the UpdatePanel know about the url's it has to show.
Each treenodebinding has a valuefield property (This value is not displayed to the user it's hidden on the page.).
If you set it then you can retrive the value in the code-behind:
YourTreeView.SelectedNode.Value --> the selected node value property.
YourTreeView.SelectedNode.ValuePath --> each node value separated by the treeview PathSeparator from the root to the selected node.
Thank you
I have thought about this. But what i really don't understand is how to tell the updatepanel, which hosts the ContentPlaceHolder what to load.
On the SelectedNodeChanged event, i get the url from the Value field, and then what? To whom should i pass that url?
Sorry, but you cannot use up that way. The up won't load a content from an url (from a different aspx) page.
You may have tried this already and are looking for an alternate way, but this is surely a case for an iframe..
Add an iframe to the page ( don't see why you can't place this inside your updatepanel) and set the selected url to the 'src' attribute of the iframe. This will then load the target content into the iframe, and the update panel should allow you to control the partial postback (not sure if you will need it as the postback from the iframe will be containted within it's own page).
Thank you both for the help
My boss has told me today that what i'm trying to do is a wrong way to use AJAX, so i guess that this issue is resolved. The idea with an iframe is good though
Hi,
Here 's what I do:
1. The "leaf" nodes are calling javascript function that updates a HiddenField.
2. The Grid is inside a UpdatePanel and has a Trigger on the HiddenField ValueChanged event.
To activate the HiddenField trigger, I call _doPostBack('hiddenfield_name', ''); at the end of the javascript function...
Hope it helps,
Michel
Hi,
Hmm..i'm not too good at javascript. If i get it right, what you are suggesting is a way to update a gridview e.g. make it show another category. I have managed to do that but with datalist in my case. I just put an index of a category inside the Value field of a treenode, and leave the navigateurl blank. On page_load event i check which node is selected and if something is selected a read it's Value field and then call a function which retrieves content from the database, depending on the fetched index.
What i was trying to do was to load a completely different page with another set of controls via UpdatePanel. But as far as i understood you can't do that (well maybe if you use an iframe you can)
Then maybe the "update panel" is not ideal to load a different page.
If the tree is in a "master page", you could use a simple hyperlink to load a different "content page"...
Sorry, I got mixed-up by the thread subject.