I have to call javascript function from javascript file codebehind .aspx page . Presently I am using this syntax which is giving me an error.
this.Page.ClientScript.RegisterClientScriptInclude
("showalert('invalidusername','password')","/Public/JS/FailLogin.js");
You’re calling the right method but as Guffa says, you’re passing it invalid parameters.
Try something like this instead:
Or if you want inline script:
Or to pass in some more dynamic script:
Please note that in the last example you most JavaScript encode the value of the “name” field. Depending on the version of .NET, one way to do it is this:
And then pass the encoded name to the “script” variable.
You can even call both methods if you want to both include a JS file as well as run some code that depends on the newly included JS file (the script include should be rendered before the script block).