CodeVerge.Net Beta


   Explore    Item Entry   Register  Login  
Microsoft News
Asp.Net Forums
IBM Software
Borland Forums
Adobe Forums
Novell Forums

ASP.NET Web Hosting – 3 Months Free!



Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 11/16/2006 2:17:30 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 3 Views: 110 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
4 Items, 1 Pages 1 |< << Go >> >|
c.unfried
Asp.Net User
TreeView - OnSelectedNodeChanged11/16/2006 2:17:30 PM

0/0

Hi!

 

I use a TreeView as sort of a Explorer Tree (I show Folders and Documents there).

If i click on a item, the OnSelectedNodeChanged is fired and i fill up a GridView with the correct data.

 So far so good.

Now to my question(s):

- Is there any chance to get the OnSelectedNodeChanged, if the already selected node is clicked?

- Can i deactivate the hyperlink of the currently selected node (means the user cannot click on the selected item anymore)?

 

Thanks for every hint.

 

Regards,

Christoph Unfried
 

pushp_aspnet
Asp.Net User
Re: TreeView - OnSelectedNodeChanged11/17/2006 7:02:47 AM

0/0

Hi c.unfried,

The answer to both of your questions above is yes but you will have to make that happen:

1) To accomplish the first functionality, try the following:

    a)put a hidden variable in your page having the treeview( with id="Tree1", say) as:

           <input type="hidden" id="hdnTvSelNodeText" runat="server"/>

    b)put the below code inside your head tag in .aspx

      <script type="text/javascript">
            window.onload = function(){

             var treeview = document.getElementById("<%=Tree1.ClientID %>");
             var treeLinks = treeview.getElementsByTagName("a");
             for(i=0;i<treeLinks.length;i++)
                 {
                      if(treeLinks[i].firstChild.tagName != "IMG")
                          {
                                            
                              treeLinks[i].onclick =function(){
           
                                       document.getElementById("<%=hdnTvSelNodeId.ClientID%>").value = this.innerText;
                                   }

                          }
                  }
    }

   c)put the following code in your page  load as:

       protected void Page_Load(object sender, EventArgs e)
           {
                if (Tree1.SelectedNode != null && Tree1.SelectedNode.Text == hdnTvSelNodeId.Value)
                    {
                        Tree1_SelectedNodeChanged(sender, e); //this is the event handler for the OnSelectedNodeChanged event
                    }

 That's all for this case.

2)For the solution to the second problem:

     a)put a hidden variable in your page having the treeview( with id="Tree1", say) as:

           <input type="hidden" id="hdnTvSelNodeText" runat="server"/>

       b)put the below code inside your head tag in .aspx

      <script type="text/javascript">
            window.onload = function(){

             var treeview = document.getElementById("<%=Tree1.ClientID %>");
             var treeLinks = treeview.getElementsByTagName("a");
             for(i=0;i<treeLinks.length;i++)
                 {
                      if(treeLinks[i].firstChild.tagName != "IMG")
                          {

                                if(document.getElementById("<%=hdnTvSelNodeId.ClientID%>").value == treeLinks[i].innerText)
                                   {
                                        treeLinks[i].setAttribute("href","javascript:void(0);");
                                   }

                                            
                              treeLinks[i].onclick =function(){
           
                                       document.getElementById("<%=hdnTvSelNodeId.ClientID%>").value = this.innerText;
                                   }
                          }
                  }
    }

That's all for the second case.

Note that above two cases are mutually exclusive.

Hope this helps.

cheers!! 


Home Is Where the Wind Blows
http://pushpontech.blogspot.com
pushp_aspnet
Asp.Net User
Re: TreeView - OnSelectedNodeChanged11/17/2006 7:06:52 AM

0/0

One minor problem above: hdnTvSelNodeId.ClientID  must be  hdnTvSelNodeText.ClientID  whereever used, i forgot to update the references at the last moment, sorry for that.

Home Is Where the Wind Blows
http://pushpontech.blogspot.com
c.unfried
Asp.Net User
Re: TreeView - OnSelectedNodeChanged11/20/2006 2:24:37 PM

0/0

Thank you for great answer.

It inspired me to my solution for this problem.

The name of each node is not unique in my case, that's why i decided to add a little javascript to my currently selected Treenode. This javascript sets a hidden Field.

 
Here is the code of my solution, which works for me:

.ASPX:

<asp:HiddenField ID="ExplorerTreeSelectedClicked" Value="false" runat="server" />

 

 .ASPX.cs:

protected void Page_Load(object sender, EventArgs e)
{

                InjectLoadEvent();
                if (ExplorerTreeSelectedClicked.Value == "true")
                {
                    // this is my Selected event method
                    ExplorerTree_Selected(sender, e);
                    ExplorerTreeSelectedClicked.Value = "false";
                }

  private void InjectLoadEvent()
        {
            string javaScript =
                "var elem = document.getElementById('" + ExplorerTree.ClientID + "_SelectedNode');\n" +
                "if(elem != null && elem.value != '')\n" +
                "{\n" +
                "  var selectedNode = document.getElementById(elem.value);\n" +
                "  var newOnClick = selectedNode.getAttribute('onclick');\n" +
                "  newOnClick += 'document.getElementById(\\'" + ExplorerTreeSelectedClicked.ClientID + "\\').value=true';\n" +
                "  selectedNode.setAttribute('onclick', newOnClick);\n" +
                "}\n";

            Page.ClientScript.RegisterStartupScript(this.GetType(), "LoadEvent", javaScript, true);
        }

4 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Beginning ASP.NET 2.0 Databases: Beta Preview Authors: John Kauffman, Thiru Thangarathinam, Pages: 404, Published: 2005
Core Internet Application Development with ASP.NET 2.0 Authors: Randy Connolly, Pages: 1049, Published: 2007
Professional ASP.NET 3.5: In C# and VB Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1673, Published: 2008
10 Coding4Fun Projects with .NET: Programming Projects for Wiimote, YouTube, World of Warcraft, and More Authors: Dan Fernandez, Brian Peek, Pages: 528, Published: 2008
Professional SQL Server 2005 Integration Services Authors: Brian Knight, Allan Mitchell, Darren Green, Douglas Hinson, Kathi Kellenberger, Andy Leonard, Erik Veerman, Jason Gerard, Haidong Ji, Mike Murphy, Pages: 692, Published: 2006
ASP.NET AJAX Programmer's Reference: With ASP.NET 2.0 Or ASP.NET 3.5 Authors: Shahram Khosravi, Pages: 1522, Published: 2007
ASP.NET 2.0数据库入门经典 Authors: 考夫曼, Pages: 400, Published: 2006
ASP.net 2.0 Illustrated: [deutsche Ausgabe] Authors: Alex Homer, Alex Homer Dave Sussman, Dave Sussman, Pages: 0, Published: 2007
ASP.net 3.5 mit Visual C# 2008 Programmieren: Grundlagen, Programmiertechniken, Datenbanken Authors: Tobias Hauser, Jürgen Kotz, Christian Wenz, Tobias Hauser, Karsten Samaschke, Jürgen Kotz, Karsten Samaschke, Christian Wenz, Pages: 1168, Published: 2008
C Sharp, ASP.Net Microsoft Ajax entraînez-vous à créer une suite bureautique en ligne avec Visual Studio 2005 Les TP informatiques: Entraînez-vous à créer une suite bureautique en ligne avec Visual Studio 2005 Authors: Brice-Arnaud Guérin, Joëlle Musset, Pages: 324, Published: 2007

Web:
TreeView.OnSelectedNodeChanged Method (System.Web.UI.WebControls) Raises the SelectedNodeChanged event of the TreeView control.
TreeView: OnSelectedNodeChanged not firing?? Talk about TreeView: OnSelectedNodeChanged not firing??
TreeView OnSelectedNodeChanged does not execute - ASP.NET Forums From my research, the onclick equivalent for TreeView is OnSelectedNodeChanged, which I set in my aspx code below: ...
Treeview server control OnSelectedNodeChanged event not executed. When you define the OnSelectedNodeChanged event handler for treeview server control, you suppose this handler is executed when users select a node in the ...
Page 2 - TreeView Part 1 - Populating the New TreeView Control ... . Now if you need to, you can begin modifying the ...
TreeView: OnSelectedNodeChanged not firing?? TreeView: OnSelectedNodeChanged not firing?? microsoft.public.dotnet.framework. aspnet. Author. 16 Dec 2005 12:47 PM. Dotnet Gruven ...
TreeView -- SelectedNode : treeview, onselectednodechanged Ive been struggling with the TreeView Control in my web forms app. How on earth does this work? Ive seen a ton of examples that says to simply call it by ...
TreeView: OnSelectedNodeChanged not firing?? TreeView: OnSelectedNodeChanged not firing?? - Microsoft ASP .NET. Visit our forum to discuss TreeView: OnSelectedNodeChanged not firing??
[2005] MasterPage, TreeView OnSelectedNodeChanged - VBForums [2005] MasterPage, TreeView OnSelectedNodeChanged ASP.NET.
aspnet TreeView: OnSelectedNodeChanged not firing?? 12/21/2005 9:03:24 AM Re: TreeView: OnSelectedNodeChanged not firing?? Kevin, Is this issue still open? Thanks geo "Kevin Yu [MSFT]" ...




Search This Site:










get size of data returned in sql query

is there a way to disable autopostback on a button control?

dynamically generating listitems for a select drop down from a dataset

how to save the status of a <asp:listbox> after postback?

firefox onclick event prevents code behind firing

binding data to a label

valueschanged event

valid url expression

capture subset of string.

enter key + cursor focus

one xml or table displaying 7 different banner ads

checking against keywords

how to use ftp to transfer file from client to server...

adding controls programatically without using a placeholder

dropdownlist's autopostback causes javascript "access denied"

delegate for dropdownlist select index change event in user control

site map w/dynamic pages ?

tell me web forms internal of asp.net ?

data entry table in c#.net

? microsoft® office html and xml reference

create search box

i need to download data to excel

textbox control problems with < char

a retrieve question.

problem with dropdownlist

lossing page title

fragment caching problem on postback

add sum with checkbox

bind data with textboxes

autopostback query string with gridview issue

  Privacy | Contact Us
All Times Are GMT