0

I'm trying to have my script tags include the attribute defer="true" when used like so

string path = "~/scripts/v_wall.js";
Page.ClientScript.RegisterClientScriptInclude(typeof(SlideShow), "defaultslideshow", ResolveUrl(path));

How can I have this method render the script tag like so?

<script defer = "true" type="text/javascript">

     <!-- etc... -->

</script>

Many thanks!

2 Answers 2

4

Why not to use the method RegisterClientScriptBlock instead? http://msdn.microsoft.com/en-us/library/btf44dc9.aspx

I guess that should be something like..

string scriptstr = "<script defer='true' type='' src=''></script>";
Page.ClientScript.RegisterClientScriptBlock(typeof(SlideShow), "defaultslideshow", scriptstr);

Good luck

0

I think that you will need to emit the script tags yourself. In order to get it added to the page as early as possible in case that something in the page needs the javascript as soon as possible.

To do this, you can add them to the page header:

var sbText = new System.Text.StringBuilder(500);
// ToDo: Add your script to the textbuilder here
this.Page.Header.Controls.Add(New LiteralControl(sbText.ToString()));

Not the answer you're looking for? Browse other questions tagged or ask your own question.