3

ASP.NET 2.0 provides the ClientScript.RegisterClientScriptBlock() method for registering JavaScript in an ASP.NET Page.

The issue I'm having is passing the script when it's located in another directory. Specifically, the following syntax does not work:

ClientScript.RegisterClientScriptBlock(this.GetType(), "scriptName", "../dir/subdir/scriptName.js", true);

Instead of dropping the code into the page like this page says it should, it instead displays ../dir/subdir/script.js , my question is this:

Has anyone dealt with this before, and found a way to drop in the javascript in a separate file? Am I going about this the wrong way?

3 Answers 3

5

What you're after is:

ClientScript.RegisterClientScriptInclude(this.GetType(), "scriptName", "../dir/subdir/scriptName.js")
Sign up to request clarification or add additional context in comments.

Comments

2

use: ClientScript.RegisterClientScriptInclude(key, url);

Comments

-1

Your script value has to be a full script, so put in the following for your script value.

<script type='text/javascript' src='yourpathhere'></script>

1 Comment

Could you please extend the answer?

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.