Consider to develop a web control (ASP.NET). What you would really like to do is styling and developing this control in a very good way, here's a very good way to do this (this is how I would like to do, further in this question I will explain why I cannot do this).
A programmatic approach
1) I create my control in a separate folder called WebControls
and I name it (for example) MyWebControl
. I will have these files: MyWebControl.ascx
and MyWebControl.ascx.cs
.
2) Given that my control is a complex control I associate a style and a dynamic client behavior referencing, in the control html, a css stylesheet called MyWebControl.ascx.css
and a javascript file called MyWebControl.ascx.js
.
3) In my control I do the following:
<%@ Control Language="C#"
AutoEventWireup="true"
CodeFile="MyWebControl.ascx.cs"
Inherits="MyApp.WebControls.MyWebControl" %>
<link href="MyWebControl.ascx.css" rel="stylesheet" type="text/css" />
<script src="MyWebControl.ascx.js" type="text/javascript"></script>
<div>
...
</div>
This is it!
The problem
Well there is a problem in this thing: when my control is rendered, and in a page there is more than one of this control of mine, I get the links to the css and js file duplicated or even repeated more than once.
How to link an external stylesheet/javascript file in my control without occurring in this bad stuff?
EDIT
OK, after looking a bit, with the help of others here in the community, I could understand that Page.ClientScript
is what comes to the rescue.
However, there are a lot of functionality for a script to be registered... can you tell the difference among these?
1) Page.ClientScript.IsClientScriptBlockRegistered
2) Page.ClientScript.IsClientScriptIncludeRegistered
3) Page.ClientScript.IsOnSubmitStatementRegistered
4) Page.ClientScript.IsStartupScriptRegistered
And the corresponding set methods?
1) Page.ClientScript.RegisterClientScriptBlock
2) Page.ClientScript.RegisterClientScriptInclude
3) Page.ClientScript.RegisterOnSubmitStatement
4) Page.ClientScript.RegisterStartupScript
Furthermore: can this be applied to javascript and css too?
Thankyou