473,385 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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_SelectedNodeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tvwMain.SelectedNodeChanged

If tvwMain.SelectedValue.ToUpper = "EXIT" Then

Response.Write("<script language='javascript'
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 5550
On Jan 25, 1:06 am, "Antonio" <antoni...@hotmail.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, myTreeViewcontrol 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_SelectedNodeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tvwMain.SelectedNodeChanged

If tvwMain.SelectedValue.ToUpper = "EXIT" Then

Response.Write("<script language='javascript'
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.getElementById("<%=Tree1.ClientID %>"); //
use your treeview id instead of Tree1
var treeLinks = treeview.getElementsByTagName("a");
for(i=0;i<treeLinks.length;i++)
{
if(treeLinks[i].firstChild.tagName != "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.selectaction to selectaction.select
to show hand on the treenode hover.

Hope this helps.

Jan 30 '07 #2
On Jan 25, 1:06 am, "Antonio" <antoni...@hotmail.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, myTreeViewcontrol 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_SelectedNodeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tvwMain.SelectedNodeChanged

If tvwMain.SelectedValue.ToUpper = "EXIT" Then

Response.Write("<script language='javascript'
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...@hotmail.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, myTreeViewcontrol 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_SelectedNodeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles tvwMain.SelectedNodeChanged

If tvwMain.SelectedValue.ToUpper = "EXIT" Then

Response.Write("<script language='javascript'
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.getElementById("<%=Tree1.ClientID %>"); //
use your treeview id instead of Tree1
var treeLinks = treeview.getElementsByTagName("a");
for(i=0;i<treeLinks.length;i++)
{
if(treeLinks[i].firstChild.tagName != "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.selectaction to selectaction.select
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
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...
3
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...
6
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....
2
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...
8
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...
1
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...
2
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...
1
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...
0
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.