ResourceManager confusion upgrading to 5.3 from 1.7

  1. #1

    ResourceManager confusion upgrading to 5.3 from 1.7

    -- Oops, I posted this in the wrong thread -- moving it to 5.x classic help thread. my apologies.

    In Ext.Net 1.7 we defined a ResourceManager in the master page because we needed to load some js resources in that master page. Then, in child pages we would use the ResourceManagerProxy to load js resouces needed by that child page. In 5.3 the ResourceManagerProxy is no longer used. So, in the child pages I attempt to use ResourceManager.GetInstance() in order to get the ResourceManager and then use it to load the js resources, trouble is that ResourceManager.GetInstance() returns null.

    It's worth noting, I tried to just use ResourceManager in the child page but then I get an error that ResourceManager can only be used once per page.

    Here is what I'm trying to do:

    In the master page:

    <body>
        <ext:ResourceManager runat="server" ID="BLResourceManager"/>
    
        <script runat="server">
            protected void Page_Load(object sender, EventArgs e)
            {
               BLResourceManager.RegisterClientScriptInclude("scripts-common", ResolveUrl("~/Scripts/Common/common.js"));
            }
        </script>
    The above is just a snippet to give an idea of what is going on, it loads the common.js just fine

    Then, in a child page, I need to load some resources but I cannot get a handle on the ResourceManager. I've tried everything I could find, but it always turns out to be null.

    Maybe this is unconventional or uncommon, but it is how this system was written. Ultimately I need to use the ResourceManager in the master and in child pages and looking for the best approach.

    <%@ Page Title="Login" Language="C#" MasterPageFile="~/Views/Shared/ExtBorderLayout.Master" Inherits="System.Web.Mvc.ViewPage" %> 
     
    <asp:Content ID="ContentMain" ContentPlaceHolderID="MainContent" runat="server"> 
    
        <Script runat="server" type="text/C#"> 
    
            protected void Page_Load(object sender, EventArgs e)
            {
                var rm = ResourceManager.GetInstance();
    // rm is null here, and I just don't understand how to get the ResourceManager in the child page
                rm.RegisterClientScriptInclude("scripts-child-script", ResolveUrl("~/Scripts/child-script.js"));
            }
        </Script>
    Last edited by bryanparke; Jul 06, 2023 at 12:39 PM.
  2. #2
    Hello, @bryanparke, and welcome back to Ext.NET after so long!

    It's kind of a big step, upgrading from 1.x to 5.x, and you are in the right path with the ResourceManager.GetInstance() change. But perhaps you don't really need to include the javascript via ResourceManager.RegisterClientScriptInclude().

    What if you try to include the script straight to the page as an ordinary <script src="~/Scripts/Common/common.js"></script>?

    Do you require it either before or after Ext.NET resources' inclusion (scripts and CSS)? I believe you can handle that with <ext:ResourcePlaceHolder runat="server" />, so maybe it becomes more intuitive and easier to maintain? The approach you're trying is only required if your script must run after Ext.NET resources are loaded, but before Ext.NET Page's init script has been included and parsed.

    The problem here is that I can't reproduce the issue you have (var rm = ResourceManager.GetInstance(); being null), so maybe there's something else in your project preventing the code to work. Could you consistently reproduce this in a simplified test case, so we get to the same page?

    In my test in a random page with master, if I add this to the master page:

    protected void Page_Load(object sender, EventArgs e)
    {
        ResourceManager1.RegisterClientScriptInclude("scripts-common", ResolveUrl("~/Scripts/Common/common.js"));
    }
    Then this to the actual ASPX page:

    protected void Page_Load(object sender, EventArgs e)
    {
        var rm = ResourceManager.GetInstance();
        rm.RegisterClientScriptInclude("scripts-child-script", ResolveUrl("~/Scripts/child-script.js"));        
    }
    The rendered page becomes:

    <Ext.NET static script includes>
    <script type="text/javascript" src="/Scripts/child-script.js"></script>
    <script type="text/javascript" src="/Scripts/Common/common.js"></script>
    <Ext.NET dynamic script include (init script)>
    So there must be something else in your project getting in the way of ResourceManager.GetInstance(). Maybe you could experiment with the Ext.NET Examples project? There are a couple examples with master page (Events > Direct Method > ID Mode, Message Bus > Basic > Complex) you could get started.

    Looking forward to your follow-up!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. [CLOSED] Window layout confusion
    By cwolcott in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 23, 2014, 4:27 PM
  2. FormPanel confusion
    By drewm in forum 1.x Help
    Replies: 1
    Last Post: Mar 10, 2014, 8:03 PM
  3. Need help upgrading from 1.x to 2.x
    By wexman in forum 2.x Help
    Replies: 1
    Last Post: Jun 06, 2013, 11:28 AM
  4. [CLOSED] Store GetChangedData and Phantom record confusion
    By jchau in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Mar 21, 2013, 7:12 AM
  5. upgrading from 0.8.1 to 0.8.2
    By Kamal in forum 1.x Help
    Replies: 4
    Last Post: Apr 08, 2010, 5:52 PM

Posting Permissions