TreeView + SiteMapDataSource + postback causes error

Jul 23, 2010 at 1:59 PM
Edited Jul 23, 2010 at 2:08 PM

The combination of using a TreeView bound to a SiteMapDataSource with the CSS friendly adapter AND something on a page that causes a postback causes a javascript error. To reproduce this issue, create a Web Site with a web.sitemap file, a default.aspx page, an App_Code folder containing TreeViewAdapter.cs and WebControlAdapterExtender.cs, and the App_Browsers folder containing CSSFriendlyAdapters.browser.

web.sitemap:

<siteMap>
  <siteMapNode url="~/Default.aspx" title="Home">
  </siteMapNode>
</siteMap>

Default.aspx:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
</head>
<body>
    <form id="form1" runat="server">
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:TreeView ID="TreeView1" runat="server" DataSourceID="SiteMapDataSource1" />
        <asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server"  />
    </form>
</body>
</html>

CSSFriendlyAdapters.browser:

<browsers>
    <browser refID="Default"> <controlAdapters>
            <adapter controlType="System.Web.UI.WebControls.TreeView"
                     adapterType="CSSFriendly.TreeViewAdapter" />
        </controlAdapters>
    </browser>

    <browser id="W3C_Validator" parentID="default">
        <identification>
            <userAgent match="^W3C_Validator" />
        </identification>
        <capabilities>
            <capability name="browser"              value="W3C Validator" />
            <capability name="ecmaScriptVersion"    value="1.2" />
            <capability name="javascript"           value="true" />
            <capability name="supportsCss"          value="true" />
            <capability name="supportsCallback"     value="true" />
            <capability name="tables"               value="true" />
            <capability name="tagWriter"            value="System.Web.UI.HtmlTextWriter" />
            <capability name="w3cdomversion"        value="1.0" />
        </capabilities>
    </browser>
</browsers>

Browse to the Default.aspx page, then click the button. The error is in this code which is automatically generated and can't be edited:

<script type="text/javascript"> //<![CDATA[ function WebForm_OnSubmit() { document.getElementById('ctl02').value = GetViewState__AspNetTreeView('TreeView1_UL'); return true; } //]]> </script>