Add <Script ... /> tag within <Head ... /> tag in ServerControl (ASP.NET)?

14,340

You can register custom scripts using the ClientScriptManager.RegisterClientScriptInclude Method during the page load. Alternatively, you can just include the script in your .aspx page. If this is a public server control, the first method is probably more preferable.

EDIT: alternatively you can register scripts in the <head> tag of the page as follows:

HtmlGenericControl jqueryInclude = new HtmlGenericControl("script");
jqueryInclude.Attributes.Add("type", "text/javascript");
jqueryInclude.Attributes.Add("src", "http://<path to jQuery>");
Page.Header.Controls.Add(jqueryInclude);
Share:
14,340
Ricardo Sampaio
Author by

Ricardo Sampaio

My projects on github: https://github.com/Mds92

Updated on June 14, 2022

Comments

  • Ricardo Sampaio
    Ricardo Sampaio almost 2 years

    I'm gonna use JQuery files in my custom ServerControl , thus I have to add below line within Head tag.

    <script type="text/javascript" src="jquery-1.4.3.min.js"></script>
    

    How can I do it in ServerControl with C#