TreeView + SiteMapDataSource + postback causes error

Jul 23, 2010 at 2:59 PM
Edited Jul 23, 2010 at 3: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.


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


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<html xmlns="">
<head runat="server">
    <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"  />


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

    <browser id="W3C_Validator" parentID="default">
            <userAgent match="^W3C_Validator" />
            <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" />

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>