473,670 Members | 2,527 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView: How to call client script on node selected?

Hi,

I would like to have my TreeNode to call window.close(); without posting
back, how can I do that? At the same time, I prefer to have a SelectAction
property that allows my TreeNode to appear as hyperlink with hand-cursor
when hover.

For your information, my TreeView control is on a master page. I have done
some tricks but when clicking the node, it does the post-back and my page
appears empty with nothing on it except the popup message box confirming to
close the browser. Below is the code:

Protected Sub tvwMain_Selecte dNodeChanged(By Val sender As Object, _
ByVal e As System.EventArg s) Handles tvwMain.Selecte dNodeChanged

If tvwMain.Selecte dValue.ToUpper = "EXIT" Then

Response.Write( "<script language='javas cript'
type='text/javascript'>")
Response.Write( "window.close() ;")
Response.Write( "</script>")
End If
End Sub

This is not a good solution. Anybody have better solution? Thanks in
advance.

Regards,
Antonio

Jan 25 '07 #1
2 5568
On Jan 25, 1:06 am, "Antonio" <antoni...@hotm ail.comwrote:
Hi,

I would like to have my TreeNode to call window.close(); without posting
back, how can I do that? At the same time, I prefer to have a SelectAction
property that allows my TreeNode to appear as hyperlink with hand-cursor
when hover.

For your information, myTreeViewcontr ol is on a master page. I have done
some tricks but when clicking the node, it does the post-back and my page
appears empty with nothing on it except the popup message box confirming to
close the browser. Below is the code:

Protected Sub tvwMain_Selecte dNodeChanged(By Val sender As Object, _
ByVal e As System.EventArg s) Handles tvwMain.Selecte dNodeChanged

If tvwMain.Selecte dValue.ToUpper = "EXIT" Then

Response.Write( "<script language='javas cript'
type='text/javascript'>")
Response.Write( "window.close() ;")
Response.Write( "</script>")
End If
End Sub

This is not a good solution. Anybody have better solution? Thanks in
advance.

Regards,
Antonio
Hi antonio,

Try putting the below script in the head of your master page:
----------------------------------------------
<script type="text/javascript">
window.onload = function(){

var treeview = document.getEle mentById("<%=Tr ee1.ClientID %>"); //
use your treeview id instead of Tree1
var treeLinks = treeview.getEle mentsByTagName( "a");
for(i=0;i<treeL inks.length;i++ )
{
if(treeLinks[i].firstChild.tag Name != "IMG")
{

treeLinks[i].onclick = function(){

//do whatever you need to do
on the click of your node
window.close();
return false; //prevents
postback
}
}
}
}</script>
--------------------------------------------------------
Additionally, set the Treeview.select action to selectaction.se lect
to show hand on the treenode hover.

Hope this helps.

Jan 30 '07 #2
On Jan 25, 1:06 am, "Antonio" <antoni...@hotm ail.comwrote:
Hi,

I would like to have my TreeNode to call window.close(); without posting
back, how can I do that? At the same time, I prefer to have a SelectAction
property that allows my TreeNode to appear as hyperlink with hand-cursor
when hover.

For your information, myTreeViewcontr ol is on a master page. I have done
some tricks but when clicking the node, it does the post-back and my page
appears empty with nothing on it except the popup message box confirming to
close the browser. Below is the code:

Protected Sub tvwMain_Selecte dNodeChanged(By Val sender As Object, _
ByVal e As System.EventArg s) Handles tvwMain.Selecte dNodeChanged

If tvwMain.Selecte dValue.ToUpper = "EXIT" Then

Response.Write( "<script language='javas cript'
type='text/javascript'>")
Response.Write( "window.close() ;")
Response.Write( "</script>")
End If
End Sub

This is not a good solution. Anybody have better solution? Thanks in
advance.

Regards,
Antonio
On Jan 25, 1:06 am, "Antonio" <antoni...@hotm ail.comwrote:
Hi,

I would like to have my TreeNode to call window.close(); without posting
back, how can I do that? At the same time, I prefer to have a SelectAction
property that allows my TreeNode to appear as hyperlink with hand-cursor
when hover.

For your information, myTreeViewcontr ol is on a master page. I have done
some tricks but when clicking the node, it does the post-back and my page
appears empty with nothing on it except the popup message box confirming to
close the browser. Below is the code:

Protected Sub tvwMain_Selecte dNodeChanged(By Val sender As Object, _
ByVal e As System.EventArg s) Handles tvwMain.Selecte dNodeChanged

If tvwMain.Selecte dValue.ToUpper = "EXIT" Then

Response.Write( "<script language='javas cript'
type='text/javascript'>")
Response.Write( "window.close() ;")
Response.Write( "</script>")
End If
End Sub

This is not a good solution. Anybody have better solution? Thanks in
advance.

Regards,
Antonio
Hi antonio,

Try putting the below script in the head of your master page:
----------------------------------------------
<script type="text/javascript">
window.onload = function(){

var treeview = document.getEle mentById("<%=Tr ee1.ClientID %>"); //
use your treeview id instead of Tree1
var treeLinks = treeview.getEle mentsByTagName( "a");
for(i=0;i<treeL inks.length;i++ )
{
if(treeLinks[i].firstChild.tag Name != "IMG")
{

treeLinks[i].onclick = function(){

//do whatever you need to do
on the click of your node
window.close();
return false; //prevents
postback
}
}
}
}</script>
--------------------------------------------------------
Additionally, set the Treeview.select action to selectaction.se lect
to show hand on the treenode hover.

Hope this helps.

Jan 30 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1530
by: Ravi | last post by:
i tried with MS treeview control but i am unable to implement all the requirements.This requiement like when user login will generate the menu and display it. After that we need to Add or remove the nodes from the tree from client side. 1.Selected node should be highlighted and non active. 2.some group of pages related to same category EX : registration process Aggrement,userinformation,login information and
3
11617
by: vijaynats | last post by:
I have a treeview with a ContextMenu attached. When i click on a node, AfterSelect fires but does not fire when right clicked (the context menu pops up). (Background: I have loaded a list of disk file names onto the tree and have to open the file thru the contextmenu for editing. It opens the file whose treeview node was selected earlier using a left mouse click). Any solutions?
6
4922
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview. However, either it only add it to the root level or it only add it on level below, doesn't matter what I select. And in some case, I just get an exception.
2
9786
by: Claus | last post by:
Hello, I have a long treeview with scrollbars. When I scroll down and press a treeview node, then the Load event fires and navigate in an iframe to another page. The problem is, that afterwards the treeview is collapsed and the node isn't selected. Expanding and selecting the node via code in the load event works, but how do I achieve, that the treeview scrolls down to the selected node? Thanks for any help Claus
8
12753
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if every time that a user selects a node, the whole page has to reload. Is there a way to have a node...
1
3594
by: Nikron | last post by:
Hi, I'm having an issue with the ASP.NET 2.0 Treeview control and persisting its' state accross requests. My Control is embedded within a master page and is used for site navigation. My problem is that the user wants to know which page they are currently on and therefore I need to highlight the selected node. The problem is I lose state whenever the user selects a node and is redirected to another page. Thanks in advance
2
5506
by: makennedy | last post by:
Hi Experts, Please help, I am a newbie to ASP.NET 2.0 may be I am doing something wrong or there may be a bug somewhere. Basically I have a TreeView Control which I have created programmatically. And I want to bind the selection of a TreeNode (which is a record) from the database) to a DetailsView which shows the datatable record for the selected TreeView node in the Details View. I am using IDE : Visual Web Developer 2005 Express; OS=...
1
3503
by: Falcula | last post by:
Hello, I have a treeview control, when i select a item i navigate to url. But selected node is lost, it reset itself, loosing state. I post my code here. Thanks in advance. <script language="javascript">
0
1896
by: Falcula | last post by:
Hello, I have a treeview that i fill from a database, when i update nodename in database the treeview dont update. Its works when iam not useing enableviewstate="true" but then i loosing the current selection and stuff in the tree. I post my code here, any idea ?
0
8810
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8590
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8659
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7410
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6211
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5683
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4208
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2035
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1790
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.