javascript error on ClientSideCommand execution

This post has 3 replies

Not Ranked
Posts: 15
acorobceanu Posted: Fri Apr 18, 2008 @ 10:04 AM
I have a sitemap configured by xml.
On one of the nodes i specify ClientSideCommand script to execute for navigation:
window.top.document.location.href='Reports.aspx?forward=24'

I do not specify NavigateUrl neither I want to.
But when i click on that node I get javascript error and then forward to correct url.
When i looked at the link being generated by the SiteMap I saw a postback call:
<code language="">javascript:if(window.top.document.location.href='Reports.aspx?forward=24'){__doPostBack(null,null);}
</code>
Last part __doPostBack() causing the javascript error.
Then I specify AutoPostBackOnSelect to False. No difference.

What is the purpose of AutoPostBackOnSelect on SiteMap item then?
Top 10 Contributor
Posts: 6,424
hwan Posted: Tue Apr 22, 2008 @ 9:21 AM
Your JavaScript is performing an assignment (not a comparison) when using only 1 equals sign (=).

I suspect you want this instead:
<code>
javascript:if(window.top.document.location.href=='Reports.aspx?forward=24'){__doPostBack(null,null);}
</code>
Not Ranked
Posts: 15
acorobceanu Posted: Tue Apr 22, 2008 @ 9:44 AM
Thanks for replying.

You did not understand. Script with errors is generated by ComponentArt control when I set ClientSideCommand on SiteMapNode.
I only set a javascript to execute.
window.top.document.location.href='Reports.aspx?forward=24'
Top 10 Contributor
Posts: 6,424
hwan Posted: Wed May 21, 2008 @ 11:00 AM
Ah, sorry for misunderstanding!

Well, this appears to be a bug -- SiteMap appears to attempt to perform some validation/conversion on the ClientSideCommand.

You can work around this by modifying your ClientSideCommand to execute nothing to avoid the __doPostBack() call.

eg.
<SiteMap>
  <node Text="Products" ClientSideCommand="window.top.document.location.href='WebForm1.aspx?forward=24'){}if(false;">
....
Page 1 of 1 (4 items)