473,499 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView 2.0 Expand/Collapse Bug when Base Target not set to _self

When using ASP.NET 2.0's built-in TreeView on a page with

<BASE target = "AnythingBut_Self"></BASE>

in the HEAD, the expand/collapse buttons fail to function. The reason
for this is that the hyperlinks generated for the expand/collapse
buttons includes javascript code that will execute in the frame
specified in the Base Target rather than the current document. To
remedy this, TreeView should render a target="_self" attribute for each
expand/collapse hyperlink.

The argument against this being a bug, of course, is that TreeView
includes a property called Target, which can be set to the desired
target (and Base Target cannot be set.) The reason I think it's better
to use Base Target is for large trees - not including a target for each
and every node saves just a little bit of extra bandwidth. (See the
JavaScript code below for my client-side work-around function called
FixTreeTargets.)

I also wasn't happy that the SelectNodeStyle isn't applied when a node
is clicked that has a NavigateUrl set, since I want the selection to be
visible while another frame shows the new page.

I created a JavaScript "wrapper" object for TreeView that allows a
selection style (I got lazy and didn't bother with SelectNodeStyle but
just a css class name instead) to be applied on click. Just call
initTheTree() from your body onload function. I haven't completely
tested this yet, but it seems to be working so far! (o;

// JScript File

var theTree;

function initTheTree() {
theTree = new ClientSideTree(document.getElementById("tvData"),
"TreeSelected", true);
}

function ClientSideTree(initTreeView, initSelectedClassName,
initCancelIfSelected) {
var objSelectedNode;
var objTreeView;
var strSelectedClassName;
var bolCancelIfSelected;
this.getTreeView = function () { return objTreeView; }
this.setTreeView = SetupTreeView;
this.getSelectedClassName = function () { return
strSelectedClassName; }
this.setSelectedClassName = function (val) { strSelectedClassName =
val; this.selectNode(objSelectedNode); }
this.getCancelIfSelected = function () { return bolCancelIfSelected;
}
this.setCancelIfSelected = function (val) { bolCancelIfSelected =
val; }
this.getSelectedNode = function () { return objSelectedNode; }
this.setSelectedNode = SelectNode;
this.selectNode = SelectNode; // Duplicate reference because it's
cool, OK!?
this.handleClick = HandleClick;
if (initTreeView)
this.setTreeView(initTreeView);
if (initSelectedClassName)
this.setSelectedClassName(initSelectedClassName);
if (initCancelIfSelected)
this.setCancelIfSelected(initCancelIfSelected);
function SetupTreeView(obj) {
objTreeView = obj;
objTreeView.onclick = this.handleClick;
FixTreeTargets();
}
function FixTreeTargets() { // Workaround for MS ASP.NET 2.0 TreeView
Bug
// Because Base Target may be set to some value other than _self,
// all Expand/Collapse link targets must be set to _self or they
will fail.
var allLinks = objTreeView.getElementsByTagName("A");
for (var i = 0; i < allLinks.length; i++) {
if (allLinks[i].href.indexOf("javascript:") > -1)
allLinks[i].target = "_self";
}
}
function HandleClick() {
//stop;
var obj = window.event.srcElement;
var objTarget;
switch (obj.tagName) {
case "A":
objTarget = obj
break;
case "IMG":
if (obj.src.indexOf("?") == -1) { // Expand/Collapse
img.src="xxx?xxx"
objTarget = obj.parentNode.parentNode.nextSibling.firstChild;
// Get Link
} else {
objTarget = null; // Ignore Expand/Collapse img
}
break;
}
window.status = "Clicked on: [" + obj.tagName + "]" + obj.id + "
src: " + obj.src;
if (objTarget) {
var prevSelectedNode = objSelectedNode;
SelectNode(objTarget);
if (objTarget == prevSelectedNode && bolCancelIfSelected)
return false; // If the selected object is reselected and
CancelIfSelected = true, cancel the click
}
}
function SelectNode(obj) {
if (objSelectedNode) {
RemoveSelectedClass(objSelectedNode);
}
if (obj) {
AddSelectedClass(obj);
objSelectedNode = obj;
}
}
function RemoveSelectedClass(obj) {
var c = obj.className;
var newClassName = "";
if (c) {
var cArray = c.split(" ");
for (var i = 0; i < cArray.length; i++) {
if (cArray[i] != strSelectedClassName) {
if (i > 0)
newClassName += " ";
newClassName += cArray[i];
}
}
obj.className = newClassName;
}
}
function AddSelectedClass(obj) {
if (obj.className && obj.className.length > 0)
obj.className += " " + strSelectedClassName;
else
obj.className = strSelectedClassName;
}
}

Don't hate the code too much - this is my first attempt at a JavaScript
object of any kind, although I've been messing with JavaScript in
general for a while.

Mar 16 '06 #1
0 2542

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

Similar topics

4
3388
by: Gönen EREN | last post by:
how can i collapse or expand a node of treeview control programmaticly? thanks.
2
2409
by: Stephen | last post by:
In asp.net 1.1, the IE treeview web control has a property called "SelectExpands" that, when set to true, expands a node when a user clicks the node text. I can't seem to replicate this in the...
1
1804
by: christoffer.lantz | last post by:
Howdy folks. Would anyone care to suggest a way to have sibling nodes (at the same level) collapse when a node is expanded in an asp.net 2.0 treeview control? What I mean is that I want only one...
3
2235
by: Shawn | last post by:
Hi. I'm working with the TreeView control in my ASP.NET 1.1 application. I have a problem I haven't been able to figure out. When I click on a node (not expand), whether it's a parent node, a...
0
2405
by: jim | last post by:
Hi, I have a TreeView control that sits on the MasterPage. All of my other webpages inherit from that Master Page. The Treeview receives it's data using an XMLDataSource that has it's DataFile...
4
8332
by: Rabel | last post by:
I am not very good at javascript I mostly am a flash developer but I am trying to apply one of our old expanding menus to work for a new site but it doesn't collapse the way I need it to right now...
0
5244
by: Tor Inge Rislaa | last post by:
I need to expand/collapse TreeView nodes to show/hide childnodes by clikcing on the node text (instead of using the expand/collapse icon). Does anyone know how to do that? (What property has to be...
0
2324
by: Tor Inge Rislaa | last post by:
Controlling TreeView Expand/Collapse With a TreeView bound to an XML file as below I want to obtain the functionality where Chapter 2 and 3 are forced to collapse when Chapter 1 is...
6
2604
by: David | last post by:
Hi all, I am opening a webform with showModalDialog. This appears to pop-up fine, though I have a problem... Inside the webform is a treeview control. When the treeview is populated, I am...
0
7007
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
7174
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,...
0
7220
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...
1
6894
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...
0
7388
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...
0
5470
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,...
1
4919
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...
0
4600
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...
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.