0

I've written a Web Control as a C# class and I want to store the CSS and JavaScript within the class itself so that when the control is generated the CSS and JS is written to the page. This is to allow me to distribute the DLL to others in my organization as 1 file, vs distributing it with an external stylesheet and external .js file. This is curiosity, and not a requirement.

Below is the basic code for the Web Control. It creates the number of DIV Containers specified in the "Columns" property of the class. The CSS formats the DIV elements, and the JavaScript/JQuery allows the users to drag & drop the columns in their preferred order.

It's added to the page with this line:

<FOO:WidgetPanel runat="server" ID="SamplePanel" />

and the Columns property is set in the Page_Load event:

SamplePanel.Columns = 3;

And here is the actual class:

namespace WebWidgets
{
    [ToolboxData("<{0}:WidgetPanel runat=server><{0}:WidgetPanel")]
    public class WidgetPanel : WebControl
    {
        [Browsable(false)]
        public int Columns { get; set; }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            base.RenderContents(writer);

            string html = "";

            for (int i = 1; i <= Columns; i++)
            {
                html += "<div  id=\"column" + i + "\" class=\"column\">";
            }

            writer.Write(html);
        }
    }
}

I think that using external files is better, but I have been asked by my management to provide a self-contained .DLL as opposed to 3 seperate files. (They also want the GUI developed before the framework so they can "see" what it looks like... Got to love it!)

Is it possible? And if so, links to a tutorial/example would be greatly appreciated.

1

1 Answer 1

1

You can add a resource file under the properties in your project, add the js and css files to it and read it using Properties.{ResourceFileName}.{YourResourceKey}. Please note that you have to change the resource type to Embedded resource to embed it in the dll.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.