Reading JavaScript File Issue

S

stephen

Hi,

I have a javascript file that I want to use on a button.

If I have the javascript file in the same folder as the webform then it
works for eg:
/SampleApp/WebForms/TestForm.aspx

but I want to try to read the javascript from another folder for e.g
/SampleApp/JScript/MyJavaScript.js

Here is my code:
if (!Page.IsClientScriptBlockRegistered("TestJavaScript"))
{
Page.RegisterClientScriptBlock("TestJavaScript", "<script
Language='JavaScript' src='MyJavaScriptFile.js'></script>");

"I want to change it to ---- src='~/JScript/MyJavaScriptFile.js'
}

btnRegisterClientScriptBlockJS.Attributes.Add("onclick",
"ConfirmationWindow();");


It does not work if i change it to second option...
any advice.
Thanks,
Stephen
 
G

Guest

Hi,

I have a javascript file that I want to use on a button.

If I have the javascript file in the same folder as the webform then it
works for eg:
/SampleApp/WebForms/TestForm.aspx

but I want to try to read the javascript from another folder for e.g
/SampleApp/JScript/MyJavaScript.js

Here is my code:
if (!Page.IsClientScriptBlockRegistered("TestJavaScript"))
{
Page.RegisterClientScriptBlock("TestJavaScript", "<script
Language='JavaScript' src='MyJavaScriptFile.js'></script>");

"I want to change it to ---- src='~/JScript/MyJavaScriptFile.js'

}

btnRegisterClientScriptBlockJS.Attributes.Add("onclick",
"ConfirmationWindow();");

It does not work if i change it to second option...
any advice.
Thanks,
Stephen

~ cannot be executed outside the ASP.NET

use src='/JScript/MyJavaScriptFile.js' or '../JScript/
MyJavaScriptFile.js'
 
G

Guest

Thanks Alexey,

the second option you suggested worked.

stephen

okay, it means that SampleApp is not a root directory, so the absolute
path must be src='/SampleApp/JScript/MyJavaScriptFile.js'

".." means parent directory (one level up in a relative path)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top