-->

Ajaxcontroltoolkit 15.1.2 Tabcontainer problems

2019-09-10 11:11发布

问题:

I've just upgraded a legacy web application from .NET 3.5 to .NET 4.5. The application extensively used the AjaxControlToolkit. Since a new version is available from May 2015, I also upgrade it.

I received several errors so I tried to create an empty project from scratch, adding the AjaxControlToolkit through Nuget, and it seems the problem is caused by the TabContainer control.

I receive the errors shown in the images below:

SCRIPT1028: Expected identifier, string or number

0x800a139e - JavaScript runtime error: Sys.ArgumentUndefinedException: Value cannot be undefined.

Obviously after those error there's no TabContainer in the page.

The strange thing is that it happens just in Internet Explorer 9+. It works like a charm in Firefox and Chrome.

The application is nearly empty, here's the relevant code from the page:

<asp:ScriptManager ID="sm" runat="server">
</asp:ScriptManager>
<ajaxToolkit:TabContainer ID="tc" runat="server">
    <ajaxToolkit:TabPanel ID="tp1" runat="server">
        <HeaderTemplate>
            Header
        </HeaderTemplate>
        <ContentTemplate>
            Content
        </ContentTemplate>
    </ajaxToolkit:TabPanel>
</ajaxToolkit:TabContainer>

Any ideas?

回答1:

It seems that you have to use Bundling to get it work.

In the project mentioned in the question I have added the AjaxControlToolkit 15.1.2 reference using nuget.

To solve the problem I have enabled bundling as explained on CodePlex:

  1. Add the reference to AjaxControlToolkit.StaticResources using nuget
  2. Change the ScriptManager to the following:

    <asp:ScriptManager runat="server">
        <Scripts>
            <asp:ScriptReference Path="~/Scripts/AjaxControlToolkit/Bundle" />
        </Scripts>
    </asp:ScriptManager>
    
  3. Add the following to the <head> element:

    <asp:PlaceHolder runat="server">
        <%: System.Web.Optimization.Styles.Render("~/Content/AjaxControlToolkit/Styles/Bundle") %>
    </asp:PlaceHolder>
    
  4. Be sure you have this in the web.config:

    <ajaxControlToolkit useStaticResources="true" renderStyleLinks="false" />