Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 675807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:51:32+00:00 2026-05-14T00:51:32+00:00

Firstly, Modifying may be the wrong term, I see a few people have posted

  • 0

Firstly, “Modifying” may be the wrong term, I see a few people have posted online just asking whether they can actually modify an embedded resource. What I am wanting to to, is use a resource in my assembly as a kind of template which I would do a find and replace on before registering it on the page – is this possible?

For example; say I have a few lines of jQuery as an embedded resource in my assembly and in this script I am referencing a CSS class name that can be set by the front-end programmer. Since I do not know what the CSS class will be until implementation, is there a way of going through the embedded resource and replacing, say, $myclass$ with ThisClassName.

Any help would be appreciated, if it’s not possible then at least tell me so I can stop chasing my tail.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T00:51:33+00:00Added an answer on May 14, 2026 at 12:51 am

    I have solved my little issue by creating an HTTP Handler. In this instance it’s called DynamicClientScript.axd.

    I have taken a few cuts from my code to give you an idea. The code below gets the standard embedded resource URL and takes the query string from it to add to the path to my handler.

        /// <summary>
        /// Gets the dynamic web resource URL to reference on the page.
        /// </summary>
        /// <param name="type">The type of the resource.</param>
        /// <param name="resourceName">Name of the resource.</param>
        /// <returns>Path to the web resource.</returns>
        public string GetScriptResourceUrl(Type type, string resourceName)
        {
            this.scriptResourceUrl = this.currentPage.ClientScript.GetWebResourceUrl(type, resourceName);
    
            string resourceQueryString = this.scriptResourceUrl.Substring(this.scriptResourceUrl.IndexOf("d="));
    
            DynamicScriptSessionManager sessMngr = new DynamicScriptSessionManager();
            Guid paramGuid = sessMngr.StoreScriptParameters(this.Parameters);
    
            return string.Format("/DynamicScriptResource.axd?{0}&paramGuid={1}", resourceQueryString, paramGuid.ToString());
        }
    
        /// <summary>
        /// Registers the client script include.
        /// </summary>
        /// <param name="key">The key of the client script include to register.</param>
        /// <param name="type">The type of the resource.</param>
        /// <param name="resourceName">Name of the resource.</param>
        public void RegisterClientScriptInclude(string key, Type type, string resourceName)
        {
            this.currentPage.ClientScript.RegisterClientScriptInclude(key, this.GetScriptResourceUrl(type, resourceName));
        }
    

    The handler then takes its query string to build the URL to the standard resource. Reads the resource and replaces each key with it’s value within the dictionary collection (DynamicClientScriptParameters).

    The paramGuid is an identifier used to get the correct script parameter collection.

    What the handler does…

            public void ProcessRequest(HttpContext context)
        {
            string d = HttpContext.Current.Request.QueryString["d"]; 
            string t = HttpContext.Current.Request.QueryString["t"];
            string paramGuid = HttpContext.Current.Request.QueryString["paramGuid"];
    
            string urlFormatter = "http://" + HttpContext.Current.Request.Url.Host + "/WebResource.axd?d={0}&t={1)";
    
            // URL to resource.
            string url = string.Format(urlFormatter, d, t);
    
            string strResult = string.Empty;
    
            WebResponse objResponse;
            WebRequest objRequest = System.Net.HttpWebRequest.Create(url);
    
            objResponse = objRequest.GetResponse();
    
            using (StreamReader sr = new StreamReader(objResponse.GetResponseStream()))
            {
                strResult = sr.ReadToEnd();
    
                // Close and clean up the StreamReader
                sr.Close();
            }
    
            DynamicScriptSessionManager sessionManager = (DynamicScriptSessionManager)HttpContext.Current.Application["DynamicScriptSessionManager"];
    
            DynamicClientScriptParameters parameters = null;
    
            foreach (var item in sessionManager)
            {
                Guid guid = new Guid(paramGuid);
    
                if (item.SessionID == guid)
                {
                    parameters = item.DynamicScriptParameters;
                }
            }
    
            foreach (var item in parameters)
            {
                strResult = strResult.Replace("$" + item.Key + "$", item.Value);
            }
    
            // Display results to a webpage
            context.Response.Write(strResult);
        }
    

    Then in my code where I want to reference my resource I use the following.

                DynamicClientScript dcs = new DynamicClientScript(this.GetType(), "MyNamespace.MyScriptResource.js");
    
            dcs.Parameters.Add("myParam", "myValue");
    
            dcs.RegisterClientScriptInclude("scriptKey");
    

    Then say my script resource contains:

    alert('$myParam$');
    

    It will output as if it was:

    alert('myValue');
    

    My code also does some caching (using the DynamicScriptSessionManager) but you get the idea…

    Cheers

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.