How to use RegisterClientScriptBlock to register JavaScript?

ASP.NET 2.0 provides a method ClientScript.RegisterClientScriptBlock()for registering JavaScript on an ASP.NET page.

The problem I encountered is passing the script when it is in another directory. In particular, the following syntax does not work:

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

Instead of dropping the code onto the page, for example this page says that it should, instead displays ../dir/subdir/script.js, my question is this:

Has anyone talked about this before and found a way to drop javascript in a separate file? Am I going about it wrong?

+3
source share
3 answers

What you need:

ClientScript.RegisterClientScriptInclude(this.GetType(), "scriptName", "../dir/subdir/scriptName.js")
+5
source

use: ClientScript.RegisterClientScriptInclude(, URL);

+2

script script, script .

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

Source: https://habr.com/ru/post/1697065/


All Articles