Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use RegisterClientScriptBlock to register JavaScript?

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?


1 Answers

What you're after is:

ClientScript.RegisterClientScriptInclude(this.GetType(), "scriptName", "../dir/subdir/scriptName.js")
like image 114
Nick Craver Avatar answered Apr 02 '26 14:04

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!