asp.net mvc stand alone ascx control how do i link (css and js) most efficiently

Posted by Julian on Stack Overflow See other posts from Stack Overflow or by Julian
Published on 2010-12-29T18:31:24Z Indexed on 2010/12/29 18:53 UTC
Read the original article Hit count: 236

Filed under:
|

Hi,

I need some advice.

I have developed some asp.net mvc web pages.
Each page has a master and some ascx controls (between 2 - 6) embedded into it a js and css file.
Up to now every thing was fine.

In order to improve modularity, flexibility and testability the ascx's are now expected to be able to work as stand alone controls.
(Each ascx has also got its own css and js files in some cases it has another control inside it)
In order to meet this requirement we call the controller with the relevant parameters and it returns the ascx (partial) directly to the browser without all of the other parts of the original page .

In order to get it to display correctly (css) and act correctly (js/jquery) all of the relevant files need to be added (as links or scripts eg. href="<%= ResolveUrl(styleSheet)%>") to the user control. This is "contradicting" the concept of positioning the files at the most logical place (could be the master page for example).

How can I overcome this problem? Keep in mind that this is relevant for each "control" ascx file.

Any thoughts will be appreciated.

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about methodology