Search code examples
asp.netjqgridasp.net-4.0scriptmanagerasp.net-optimization

register bundle for "jqgrid" in scriptmanager


I am new to bundle and optimization and trying to understand. I am creating bundle in site containing Webform and .Net Framework 4.0. I have created 'BundleConfig.cs' in which i am creating bundles. it has following code:

 public static void RegisterBundles(BundleCollection bundles)
    {
        /// JavaScript Bundles.
        // removed other standard bundles for readability.

        bundles.Add(new ScriptBundle("~/Bundles/jqGird")
                .Include("~/Scripts/jquery.jqGrid.min.js")
                .Include("~/Scripts/i18n/grid.locale-en.js")
            );
    }

I have also created 'Global.asax', which contains:

<script runat="server">
    void Application_Start(object sender, EventArgs e)
    {
        // Code that runs on application startup
        // Registering Bundles
        Sheridan.DPD.WebApp.BundleConfig.RegisterBundles(BundleTable.Bundles);

        // Enabling Bundle Optimization.
        BundleTable.EnableOptimizations = true;

    }
</script>

Now in Master page i am registering the bundle in 'ScritpManager'

<asp:ScriptManager runat="server" ID="scriptMgr" EnablePageMethods="true">
    <Scripts>
        <%--Framework scripts--%>
        <asp:ScriptReference Name="MsAjaxBundle" />
        <asp:ScriptReference Name="jquery" />
        <asp:ScriptReference Name="jquery.ui.combined" />

        <asp:ScriptReference Name="jqGird" />

        <asp:ScriptReference Name="WebForms.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebForms.js" />
        <asp:ScriptReference Name="WebUIValidation.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebUIValidation.js" />
        <asp:ScriptReference Name="MenuStandards.js" Assembly="System.Web" Path="~/Scripts/WebForms/MenuStandards.js" />
        <asp:ScriptReference Name="GridView.js" Assembly="System.Web" Path="~/Scripts/WebForms/GridView.js" />
        <asp:ScriptReference Name="DetailsView.js" Assembly="System.Web" Path="~/Scripts/WebForms/DetailsView.js" />
        <asp:ScriptReference Name="TreeView.js" Assembly="System.Web" Path="~/Scripts/WebForms/TreeView.js" />
        <asp:ScriptReference Name="WebParts.js" Assembly="System.Web" Path="~/Scripts/WebForms/WebParts.js" />
        <asp:ScriptReference Name="Focus.js" Assembly="System.Web" Path="~/Scripts/WebForms/Focus.js" />
        <asp:ScriptReference Name="WebFormsBundle" />
        <%--Site scripts--%>
    </Scripts>
</asp:ScriptManager>

It is giving me following error.

System.InvalidOperationException: 'jqGird' is not a valid script name. The name must end in '.js'.

So what is it that I am doing wrong? as other Bundles are working fine.


Solution

  • You'll need to register all of your scripts together as jqGird using ScriptManager Class

    ScriptManager.ScriptResourceMapping.AddDefinition("jqGird", new ScriptResourceDefinition
    {
       Path = "~/Bundles/jqGird", 
    });
    

    You can also refer to ASP.NET 4.5 ScriptManager Improvements in WebForms