Todd Vance
Todd Vance

Reputation: 4711

How would I add jquery, css, etc. from my HEAD into a aspx user control?

I have a page with this in the head

<style type="text/css">
    #columnList { list-style-type: none; margin: 0; padding: 0; width: 95%; }
    #columnList li { margin: 0 3px 3px 3px; padding: 0.1em; padding-left: 1.5em; font-size: 1.4em; height: 18px; }
    #columnList li span { position: absolute; margin-left: -1.3em; }
    .column { font-size: small; border:1px solid; background-color: lightyellow; }
     body { background : beige }
</style>
<link rel="StyleSheet" href="css/dashCss.css" type="text/css" media="screen" />
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jcolor/jscolor.js"></script>
<script type="text/javascript" src="js/dashboard.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.js"></script>    

And now I want to move that page into an aspx user control but dont know what to do with the head stuff... help?

Upvotes: 0

Views: 576

Answers (1)

Brian Mains
Brian Mains

Reputation: 50728

1) Either add it to the pages that will use the user control manually or 2) If you use the ASP.NET AJAX framework, use the ScriptManager and ScriptManagerProxy to manage your scripts. ScriptManager goes at the top of the page, or in the master page, and ScriptManagerProxy can go in any number of user controls. You can put the ScriptManagerProxy in your user control, register your scripts in the section, and these get wired up to the ScriptManager and registered at the ScriptManager location.

In the user control, the ScriptManagerProxy would look like:

<asp:ScriptManagerProxy id="smp" runat="server">
  <Scripts>
     <asp:ScriptReference Path="~/js/jquery.js" />
  </scripts>
</asp:ScriptManagerProxy>

Just make sure that the site master page or the page using this user control has this at the top, but within the form.

<asp:ScriptManager id="sm" runat="server" />

Or 3) Programmably add them from code-behind; get the pages header reference, and add script tags programmatically.

Upvotes: 1

Related Questions