CodeVerge.Net Beta


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




Can Reply:  No Members Can Edit: No Online: Yes
Zone: > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls Tags:
Item Type: NewsGroup Date Entered: 11/21/2006 1:09:57 AM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
NR
XPoints: N/A Replies: 6 Views: 486 Favorited: 0 Favorite
7 Items, 1 Pages 1 |< << Go >> >|
cjlauziere
Asp.Net User
Adding "OnClientClick" to treeview node...11/21/2006 1:09:57 AM

0

Hello, all.

I'm trying to add an "OnClientClick" event to treenodes in the treeview, so that I can run a javascript function as well as postback to the page.

 This function simply displays a "processing" layer until the page unloads and redirects to the new page.

I have no problem calling the function on the page "onbeforeunload" event.  But, that's not suitable because even expanding a plus sign on the treeview invokes this message, but the page never really unloads, so the layer never disappears.  So, I'm hoping to call this function instead with the "OnClientClick" event instead.

I figure I should be using the OnTreeNodeDataBound method to accomplish this, but can't quite figure it out.

Much appreciated for any help.

 Thanks,

Loz

pushp_aspnet
Asp.Net User
Re: Adding &quot;OnClientClick&quot; to treeview node...11/21/2006 5:26:34 AM

1

Hi,

Try putting the below code inside the head tag of your page:

------------------------------------------------------------------- 

window.onload = function(){

     var treeview = document.getElementById("<%=Tree1.ClientID %>"); //use your treeview  id in place of  Tree1
     var treeLinks = treeview.getElementsByTagName("a");
     for(i=0;i<treeLinks.length;i++)
     {
          if(treeLinks[i].firstChild.tagName != "IMG")
          {
                  
              treeLinks[i].onclick = treeNodeClickHandler;  //setting the client function to be called on treenode click
              
          }
      }
}

function treeNodeClickHandler()  //put the code  that will run when node is clicked, inside this function
{
    alert(this.innerText);  // 'this' refers to the clicked node
}

------------------------------------------------------------------------
 

Hope this helps.

cheers!! 

 


Home Is Where the Wind Blows
http://pushpontech.blogspot.com
cjlauziere
Asp.Net User
Re: Adding &quot;OnClientClick&quot; to treeview node...11/21/2006 3:07:45 PM

-1

Thanks a lot for the suggestion.

 But now the "processing" layer simply runs all the time (as soon as the page is loaded), with no "click" event required.

 I think I'm gonna have to intercept the generation of the link in the OnTreeNodeDataBound event anyhow.

 Any ideas on that approach?

 Thanks, again.

 Loz

pushp_aspnet
Asp.Net User
Re: Adding &quot;OnClientClick&quot; to treeview node...11/21/2006 3:32:57 PM

-1

I am not aware of your exact requirement, you may try the following(although the method is not very 'clean'):

In the handler for the OnTreeNodeDataBound, try wrapping the node text in a span as:

----------------------------------------------------------------- 

e.Node.Text = "<span onclick='javascript:myNodeClickHandler()'>"+e.Node.Text+"</span>";

-----------------------------------------------------------------

That would probably work but tooltips may show that big ugly text.

Hope that helps.

cheers!! 


Home Is Where the Wind Blows
http://pushpontech.blogspot.com
cjlauziere
Asp.Net User
Re: Adding &quot;OnClientClick&quot; to treeview node...11/21/2006 7:09:55 PM

0

Thanks, again.

 I managed to do that when the nodes were originally generated from our component.  It worked, sort of.

But, when I clicked on the link and the page posted back it lost focus and moved to the parent element.

I simply couldn't get to the proper page.

 Too bad, oh well.

I'm thinking I better consider another approach.

cjlauziere
Asp.Net User
Re: Adding &quot;OnClientClick&quot; to treeview node...11/21/2006 8:55:20 PM

0

My apolgies...

 You were right, and I was just missing another thing in my code...

So, after wasting a tonne of time checking out other solutions, I came back to your suggestion, and noticed what I was missing.

It all works perfectly...

Thank you sir...you're a genious

 

Loz

pushp_aspnet
Asp.Net User
Re: Adding &quot;OnClientClick&quot; to treeview node...11/22/2006 5:15:51 AM

0

My pleasure buddy. I'm just paying back for the help i recieved here.

Home Is Where the Wind Blows
http://pushpontech.blogspot.com
7 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
PROFESSIONAL ASP.NET 3.5 IN C# AND VB Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1728, Published: 2008
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew Macdonald, Mario Szpuszta, Pages: 1288, Published: 2005
Pro ASP.NET 2.0 in C# 2005 Authors: Matthew MacDonald, Mario Szpuszta, Pages: 1255, Published: 2005
Professional Asp.net 3.5 Sp1 Edition: In C# and Vb Authors: Bill Evjen, Scott Hanselman, Devin Rader, Pages: 1856, Published: 2009
PROFESSIONAL ASP.NET 2.0, SPECIAL EDITION Authors: Bill Evjen, Scott Hanselman, Devin Rader, Farhan Muha, Pages: 1586, Published: 2006

Web:
Adding "OnClientClick" to treeview node... - ASP.NET Forums I'm trying to add an "OnClientClick" event to treenodes in the treeview, so that I can run a javascript function as well as postback to the ...
Button.OnClientClick Set from the Behind code. - ASP.NET Forums InnerText = "Add"; button.Attributes["onclick"] = "alert('hello');"; button. RenderControl(textWriter); TreeNode bugNode = new TreeNode(sw. ...
obout inc - ASP.NET EasyMenu - Tutorials - OnClientClick Property Add / Remove Items New ... Select the TreeView node New ... OnClientClick=" menuObject.contentCell.innerHTML = prompt('Choose a new text', ...
ASP.NET Classic Controls - Treeview Forum - Problem with ... From Server side, the nodes are getting added to treeview without a page refresh correctly. OnClientClick of another button, ...
obout inc - ASP.NET EasyMenu - Tutorials - Using with TreeView add the current node's id to the string attachTo += "id" + myReader. ... OnClientClick="targetEl.parentNode.firstChild.firstChild.onclick();" ... Feel free to test on the nodes of the treeview on the right hand side of the page. ...

Adding "OnClientClick" to treeview node... - ng.asp-net-forum ... Adding "OnClientClick" to treeview node..., > ROOT > NEWSGROUP > Asp.Net Forum > general_asp.net.master_pages_themes_and_navigation_controls, ...
MasterPage, Javascript, and XHTML : Microsoft JScript runtime ... Add("onclick", "launch_job_question()") at runtime but it doesn't work because this is the same as doing OnClientClick() when the page is rendered .... asp.net 2.0 treeview doesn't work after moving to production ...












menu font color

reference datasource controlparameter in separate contentplaceholder

how to add sitemapnodes to web.sitemap?

master pages version 1.*

master pages and aspx pages

script doesnot work when using a masterpage.

sqlsitemapprovider and separators

adding node into a treeview web-control

navigation menu similar to www.asp.net menu

disable the url in root node in treeview

menu1_menuitemdatabound : menu.items.count == 1 ????

menu, sitemappath & web.sitemap

dynamic master pages

is it possible to create a user control that has a contentplaceholder?

cannot get page using master page to use enctype="multipart/data"

content place holder with visual studios

sitemappath and server.transfer woes

programmatically create menu and xmldatasource

adding master page after web forms

is it possible to create forms under contetholder.

master pages - too much flashing!

themes aint workin' here ..!

web.sitemap

treeview - node.parent is null even though it has a parent node

open a link in the content

bind sitemap to dropdownlist

roll controled sitemap nodes (hide/show without web.config)

problem setting up masterpages. can't find links an images

problem grasping how i could adapt my site to make use of the navigation controls

master page

 
Search This Site:

 
  Privacy | Contact Us
All Times Are GMT