Home - Forums-.NET - FlyTreeView (ASP.NET) - Call a Javascript in root nodes not working?

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Call a Javascript in root nodes not working?
Link Posted: 11-Dec-2007 11:13
Hi,
with a tree using nodetypes, I run into an issue if I try to call a javascript using the NavigateUrl-property. The link is a call to a function placed in a script-tag on the page. I set it like this:
      
FlyTreeNode newNode = new FlyTreeNode(nodeTitle);
newNode.Value = 123;
newNode.NavigateUrl = "javascript:MyFunction();";

Doing all this with nodes that are NOT in the root, everything works fine. My function is called etc. However, if the nodes are in the trees root, it does not work. The code is not called, but an error occurs "Object expected", debugging shows a js-Page with only one line: "MyFunction();".

E.g. the following tree:
-----------
Boss A
'- Subordinate A.1
Boss B
'- Subordinate B.1
-----------

The same NavigateUrl-property works fine at Subordinate A.1 and B.1, but not on Boss A nor Boss B.
Any ideas?
BR,
rawaho
Link Posted: 11-Dec-2007 11:26
I just created a small test case using default Office 2003 style demo.
Just modified the root node to contain
NavigateUrl="javascript:alert('a')"

And this works fine.

For your case, try to set NavigateUrl to
NavigateUrl="javascript:alert(typeof MyFunction)"

What message do you get when click it?

You can also try to use
javascript:window.MyFunction()
Link Posted: 11-Dec-2007 21:25
Hi,
I had this test-case, too. But alert is a javascript built-in function, so no matter from where you call it it will work, always. But using a custom function that itself does just call alert, it didn't work for me, symptoms as described earlier: Object expected, debugging shows an empty page with just the name of my function followed by hyphens.

Answers to your questions:
NavigateUrl="javascript:alert(typeof MyFunction)" -> undefined
javascript:window.MyFunction() -> Object expected

Looking in the code of the page, the script tag exists before the tree.
BR,
rawaho
Link Posted: 11-Dec-2007 22:51
I understand that alert is a built-in function.
Anyway the code shows that javascript works ok (node click shows message that MyFunction is undefined).

I think, there's a problem with your function visibility (for some reason). You can try to move your function code to the top of your page.

I also created an additional test.
It now contains a simple MyFunction implementation:

    function MyFunction()
    {
        alert('MyFunction');
    }


Followed by treeview with root node using  NavigateUrl="javascript:MyFunction();"

Do you use UdatePanel's partial update or some additional complex javascript frameworks?

Also, if you create a small test case, that we can run and debug locally, it will be a 100% way to solve possible bug .


Thanks.
Link Posted: 12-Dec-2007 01:38
Hi,
please don't get it wrong, just to make sure both of us are not wasting time.
- Did your testcase work with MyFunction(), if the function is in a script-block in the page?

Trying to get closer to the issue  why the function is not visible:
My debugging efforts either show the script in mypage.aspx (my code) or the webresource.axd (if I continue debugging ending up in your code). I've got only this one script-block, it appears right on top of the page before the body-tag and every single script on the page works. Assuming this, do you have any idea why debugging the call to MyFunction(), I get from the webresource.axd to an isolated 'page' or whatever, titled 'JScript - window script block', with only this single line "MyFunction();" (without hyphens). This block of course does not contain my code, this is a nirvana.
The last line in webresource.axd I hit in debugging is:
return _0[_2o]==null&&_0._o&&typeof(_0._o[_2o])!='undefined'?_0._o[_2o]:_0[_2o];}
where _0 is my node and _2o is "_4N". The value of the nodes property _4N is "javascript:MyFunction();"
Should the call be directed to mypage.aspx, but it isn't?

BR,
rawaho
Link Posted: 12-Dec-2007 03:23
rawaho,

Can you create a test page? Or some code to duplicate the problem.

In this case I'm sure I can find the reason.


from your code it comes that the error is raised from the following function (decompressed):

function fn_Node_GetProperty(ch_node, ch_propertyName)
{
    return ch_node[ch_propertyName] == null && ch_node.pt_nodeType && typeof(ch_node.pt_nodeType[ch_propertyName]) != 'undefined' ? ch_node.pt_nodeType[ch_propertyName] : ch_node[ch_propertyName];
}

Where ch_node is your node, and ch_propertyName is "NavigateUrl" (which is _4N when compressed).


Anyway I don't think this will help.

The only way is to reproduce the error in a test case.

Thanks and sorry for inconvenience.