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

Sign up to request clarification or add additional context in comments.

Comments

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()));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.