I am using a treeview in my master page and every node having link to its container page.That means click on any child node of treeview its redirect to another page by taking some value.
Now every time I click on nodes of treeview, its get collaps when child page loaded...
Now I need help regaring maintain state of treeview across my web application...
Any help with some sample are welcome....
Thank you
Mark As Answer if it helps
Thanks & Regard
Gyana Ojha
Probably i got your problem. In AJAX, even though user doesn't experience the posting a request to the server, for every async operation page life cycle will be executed. And since it is not a postback operation IsPostBack will be
false. And, thus your tree is building every time you do a async postback.
To resolve this, you need to check for IsInAsyncPostBack property. For sample and more details please visit
Thanks for your support...But the link which you provide me every time its going to else part ..can you provide me some sample ....That will be great help.....
Mark As Answer if it helps
Thanks & Regard
Gyana Ojha
gyana.ojha
Participant
770 Points
377 Posts
How to maintain state of Treeview across my application
Mar 04, 2011 04:58 AM|LINK
Hello All forum members
I am using a treeview in my master page and every node having link to its container page.That means click on any child node of treeview its redirect to another page by taking some value.
Now every time I click on nodes of treeview, its get collaps when child page loaded...
Now I need help regaring maintain state of treeview across my web application...
Any help with some sample are welcome....
Thank you
Thanks & Regard
Gyana Ojha
DigiMortal
Contributor
5658 Points
939 Posts
MVP
Re: How to maintain state of Treeview across my application
Mar 04, 2011 06:38 AM|LINK
You should use postback when user clicks on treeview node. On event fired during postback you should do two things:
When page loads and treeviews are bound to data you can select correct node from treeview if there is data in session for that treeview.
Also visit my ASP.NET blog or follow me @ Twitter:twitter.com/gpeipman
KumarHarsh
All-Star
15133 Points
3647 Posts
Re: How to maintain state of Treeview across my application
Mar 04, 2011 07:10 AM|LINK
refer this,
http://forums.asp.net/p/1657249/4318893.aspx/1?Re+maintaing+the+treeview+state+across+the+pages
Kumar Harsh
gyana.ojha
Participant
770 Points
377 Posts
Re: How to maintain state of Treeview across my application
Mar 07, 2011 05:07 AM|LINK
Hi
Thanks for your quick response.. I am generating node and child node in runtime and each node have value for navigate url.
I am not using SelectedNodeChange Event of treeview...Please give some idea...
Thanks & Regard
Gyana Ojha
bala.sekhar
Member
294 Points
62 Posts
Re: How to maintain state of Treeview across my application
Mar 07, 2011 07:10 AM|LINK
hi Gyana,
What is the version of ASP.Net you are using? If it is > 2.0 why don't you update panels with Treeview? That would completely resolve your issue.
Please mark the replies as answers if they help or unmark if not.
gyana.ojha
Participant
770 Points
377 Posts
Re: How to maintain state of Treeview across my application
Mar 07, 2011 07:45 AM|LINK
Hi
I am using Asp.net version 2.0.. I have tried with Updated panel too..But Still facing the same issue..
Thanks & Regard
Gyana Ojha
bala.sekhar
Member
294 Points
62 Posts
Re: How to maintain state of Treeview across my application
Mar 07, 2011 09:16 AM|LINK
Could you please let me know how you are using updatepanel. I mean what is the UI layout? where did you placed Treeview?
Please mark the replies as answers if they help or unmark if not.
gyana.ojha
Participant
770 Points
377 Posts
Re: How to maintain state of Treeview across my application
Mar 07, 2011 10:30 AM|LINK
Hi
Ok I am giving my exact requirement....
My master page with treeview control is like below
<table width="100%" cellpadding="0" cellspacing="0"> <tr> <td width="20%" valign="top" class="MenuContainer"> <ajax:UpdatePanel id="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:TreeView ID="trwPractice" runat="server" ImageSet="Simple" PopulateNodesFromClient="False" OnUnload="trwPractice_Unload" OnSelectedNodeChanged="trwPractice_SelectedNodeChanged"> <ParentNodeStyle Font-Bold="False" /> <HoverNodeStyle Font-Bold="False" Font-Italic="True" Font-Underline="False" /> <SelectedNodeStyle Font-Underline="True" HorizontalPadding="0px" VerticalPadding="0px" Font-Bold="True" /> <NodeStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black" HorizontalPadding="5px" NodeSpacing="0px" VerticalPadding="2px" /> </asp:TreeView> </ContentTemplate> <Triggers> <ajax:AsyncPostBackTrigger ControlID="lnbView" EventName="Click"> </ajax:AsyncPostBackTrigger> <ajax:AsyncPostBackTrigger ControlID="trwPractice" EventName="Unload"> </ajax:AsyncPostBackTrigger> </Triggers> </ajax:UpdatePanel> </td> <td style="height: 607px" valign="top"> <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server"> </asp:ContentPlaceHolder> </td> </tr> </table>and My code for Binding treenode is giving below...
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { FillNode(); } Page.Title = "eChargePosting"; }protected void FillNode() { _PracticeBLClass = new PracticeBLClass(); DataSet _ds = new DataSet(); _ds = _PracticeBLClass.GetAllPracticeName(); if (_ds.Tables[0].Rows.Count > 0) { for (int i = 0; i < _ds.Tables[0].Rows.Count; i++) { TreeNode t = new TreeNode(Convert.ToString(_ds.Tables[0].Rows[i]["PName"]), Convert.ToString(_ds.Tables[0].Rows[i]["PID"])); //t.ChildNodes.Add(GetChild(Convert.ToBoolean(_ds.Tables[0].Rows[i]["PRACTICE"]), Convert.ToString(_ds.Tables[0].Rows[i]["TYPEID"]))); t.ChildNodes.Add(GetChild(Convert.ToString(_ds.Tables[0].Rows[i]["PID"]), Convert.ToString(_ds.Tables[0].Rows[i]["PName"]))); trwPractice.Nodes.Add(t); } } trwPractice.CollapseAll(); new TreeViewState().RestoreTreeView(trwPractice, this.GetType().ToString()); } protected TreeNode GetChild(string PracticeID, string PracticeName) { TreeNode t = new TreeNode("TypeList"); t.NavigateUrl = "Default.aspx"; TreeNode tchild; DataSet _dsChild = new DataSet(); _PracticeBLClass = new PracticeBLClass(); _dsChild = _PracticeBLClass.GetPracticeWiseType(PracticeID); if (_dsChild.Tables[0].Rows.Count > 0) { for (int i = 0; i < _dsChild.Tables[0].Rows.Count; i++) { if (Convert.ToString(_dsChild.Tables[0].Rows[i]["EmpNo"]) == Convert.ToString(_dsChild.Tables[0].Rows[i]["CreatedBy"]) && Convert.ToString(_dsChild.Tables[0].Rows[i]["Category"]) == "R") { tchild = new TreeNode(Convert.ToString(_dsChild.Tables[0].Rows[i]["TYPENAME"]), Convert.ToString(_dsChild.Tables[0].Rows[i]["TypeID"])); tchild.NavigateUrl = "PageList.aspx?TypeID=" + Convert.ToString(_dsChild.Tables[0].Rows[i]["TypeID"]) + "&PrID=" + Convert.ToString(_dsChild.Tables[0].Rows[i]["XREFPrID"]) + "&PrName=" + Convert.ToString(_dsChild.Tables[0].Rows[i]["PrName"]) + ""; t.ChildNodes.Add(tchild); } if (Convert.ToString(_dsChild.Tables[0].Rows[i]["Category"]) == "P") { tchild = new TreeNode(Convert.ToString(_dsChild.Tables[0].Rows[i]["TYPENAME"]), Convert.ToString(_dsChild.Tables[0].Rows[i]["TypeID"])); tchild.NavigateUrl = "PageList.aspx?TypeID=" + Convert.ToString(_dsChild.Tables[0].Rows[i]["TypeID"]) + "&PrID=" + Convert.ToString(_dsChild.Tables[0].Rows[i]["XREFPrID"]) + "&PrName=" + Convert.ToString(_dsChild.Tables[0].Rows[i]["PrName"]) + ""; t.ChildNodes.Add(tchild); } } } return t; }Thanks & Regard
Gyana Ojha
bala.sekhar
Member
294 Points
62 Posts
Re: How to maintain state of Treeview across my application
Mar 07, 2011 11:41 AM|LINK
Probably i got your problem. In AJAX, even though user doesn't experience the posting a request to the server, for every async operation page life cycle will be executed. And since it is not a postback operation IsPostBack will be false. And, thus your tree is building every time you do a async postback.
To resolve this, you need to check for IsInAsyncPostBack property. For sample and more details please visit
http://sekhardolly.blogspot.com/2011/03/how-to-determine-whether-async-postback.html
Please mark the replies as answers if they help or unmark if not.
gyana.ojha
Participant
770 Points
377 Posts
Re: How to maintain state of Treeview across my application
Mar 08, 2011 02:51 AM|LINK
Hi Shekhar,
Thanks for your support...But the link which you provide me every time its going to else part ..can you provide me some sample ....That will be great help.....
Thanks & Regard
Gyana Ojha