Reading JavaScript File Issue

Discussion in 'ASP .Net' started by stephen, Oct 3, 2007.

  1. stephen

    stephen 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
     
    stephen, Oct 3, 2007
    #1
    1. Advertising

  2. On Oct 3, 6:39 pm, "stephen" <> wrote:
    > 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'
     
    Alexey Smirnov, Oct 3, 2007
    #2
    1. Advertising

  3. stephen

    stephen Guest

    Thanks Alexey,

    the second option you suggested worked.

    stephen

    "Alexey Smirnov" <> wrote in message
    news:...
    > On Oct 3, 6:39 pm, "stephen" <> wrote:
    >> 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'
    >
     
    stephen, Oct 3, 2007
    #3
  4. On Oct 3, 7:16 pm, "stephen" <> wrote:
    > Thanks Alexey,
    >
    > the second option you suggested worked.
    >
    > stephen
    >
    > "Alexey Smirnov" <> wrote in message
    >
    > news:...> On Oct 3, 6:39 pm, "stephen" <> wrote:
    > >> 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'


    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)
     
    Alexey Smirnov, Oct 3, 2007
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Darrel
    Replies:
    3
    Views:
    695
    Kevin Spencer
    Nov 11, 2004
  2. Shane
    Replies:
    7
    Views:
    379
    Shane
    Aug 23, 2004
  3. John

    reading text file issue

    John, Jun 2, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    367
    Cowboy \(Gregory A. Beamer\)
    Jun 2, 2006
  4. Replies:
    0
    Views:
    802
  5. Karim Ali

    Reading a file and resuming reading.

    Karim Ali, May 25, 2007, in forum: Python
    Replies:
    2
    Views:
    388
    Hrvoje Niksic
    May 25, 2007
Loading...

Share This Page