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 4033304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:49:54+00:00 2026-05-20T11:49:54+00:00

I just found an article on codeproject, which made me quite interested … So

  • 0

I just found an article on codeproject, which made me quite interested … So I’ve implemented this one here:

I have two projects:

  • MyComponent.Web (holding all the resources and controls)
  • MyComponent.Web.Demo (just the webProject)

In MyComponent.Web I have

AssemblyInfo.cs

[assembly: WebResource(WebResourceHelper.JQueryPath, "text/javascript")]

WebResourceHelper.cs

public static class WebResourceHelper
{
    internal const string JQueryPath = "MyComponent.Web.WebResources.jQuery.jquery-1.5.1.min.js";

    public static void RegisterJQuery(this Page page)
    {
        page.RegisterWebResource(JQueryPath);
    }

    public static void RegisterWebResource(this Page page, string path)
    {
        Contract.Requires(page != null);
        Contract.Requires(!string.IsNullOrEmpty(path));

        var pageType = page.GetType();
        var webResourcePath = page.ClientScript.GetWebResourceUrl(pageType, path);
        page.ClientScript.RegisterClientScriptResource(pageType, webResourcePath);
    }
}

TextBox.cs

// namespace: MyComponent.Web.UI.WebControls
public sealed class TextBox : System.Web.UI.WebControls.TextBox
{
    #region life cycle

    protected override void OnInit(System.EventArgs e)
    {
        base.OnInit(e);

        this.Page.RegisterJQuery();
    }

    #endregion
}

and additionally my script-file with build action set to Embedded Resource

In MyComponent.Web.Demo I have

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <myComponent:TextBox runat="server" ID="textBox" />
    </div>
    </form>
</body>
</html>

web.config

<system.web>
    <pages>
        <controls>
            <add tagPrefix="myComponent" namespace="MyComponent.Web.UI.WebControls" assembly="MyComponent.Web" />
        </controls>
    </pages>
</system.web>

But WebResource.axd gives me a 404, whereas Reflector shows me the, that I’ve embedded the resource correctly – so what am I doing wrong here?

Edit
You can download a demo here

  • 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-20T11:49:54+00:00Added an answer on May 20, 2026 at 11:49 am

    the nasty thing is this one here:

    this.Page.RegisterJQuery();
    

    combined with

    var webResourcePath = page.ClientScript.GetWebResourceUrl(pageType, path);
    

    page.ClientScript.GetWebResourceUrl() uses the assembly of pageType to search for the resource. As I’ve dropped the resource in another assembly instead, it can’t find it.

    So, the solution:

    TextBox.cs

    // namespace: MyComponent.Web.UI.WebControls
    public sealed class TextBox : System.Web.UI.WebControls.TextBox
    {
        #region life cycle
    
        protected override void OnInit(System.EventArgs e)
        {
            base.OnInit(e);
    
            this.RegisterJQuery();
        }
    
        #endregion
    }
    

    WebResourceHelper.cs

    public static class WebResourceHelper
    {
        internal const string JQueryPath = "MyComponent.Web.WebResources.jQuery.jquery-1.5.1.min.js";
        internal const string JQueryKey = "jQuery";
        private static readonly Type TypeOfWebResourceHelper = typeof (WebResourceHelper);
    
        public static void RegisterJQuery<TControl>(this TControl control)
            where TControl : Control
        {
            control.RegisterWebResource(JQueryKey, JQueryPath);
        }
    
        internal static void RegisterWebResource<TControl>(this TControl control, string key, string path)
            where TControl : Control
        {
            Contract.Requires(control != null);
            Contract.Requires(!string.IsNullOrEmpty(key));
            Contract.Requires(!string.IsNullOrEmpty(path));
    
            var page = control.Page;
            if (page.ClientScript.IsClientScriptIncludeRegistered(key))
            {
                return;
            }
    
            var webResourcePath = page.ClientScript.GetWebResourceUrl(TypeOfWebResourceHelper, path);
            page.ClientScript.RegisterClientScriptInclude(key, webResourcePath);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just found this out, so i am answering my own question :) Use a
I just found this in some old code, and I'm not sure what it
I’ve just found out that the execution plan performance between the following two select
I have just found RowSets for database querying with JDBC. They are stateless and
I have used the code supplied in the following CodeProject article in the past
I just stumbled on this article on MSDN that says a path can be
I just read this article on how to create global hotkeys using Carbon events.
I just found /n softwares free Powershell NetCmdlets, and after playing with them I
I just found myself creating a class called InstructionBuilderFactoryMapFactory. That's 4 pattern suffixes on
I just found out that by converting PNG32 to PNG8 via Photoshop will fix

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.