Can't get javascript file to work...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Wells

    Can't get javascript file to work...

    Hello.

    I thought this was supposed to be simple. I'm trying to use a .js file for
    my javascript functions. I'm testing by only using one function The
    function works when it's at the top of my aspx file.

    The file is called "MyFunctions.js " which was imported on the page load
    event of the code-behind form with
    Page.ClientScri pt.RegisterClie ntScriptBlock(t his.GetType(), "MyFuncs",
    "MyFunctions.js ", true); - I've used this with both true and false and with
    adding script tags myself in the .js file.

    I've also tried
    Page.ClientScri pt.RegisterClie ntScriptInclude (this.GetType() , "MyFuncs",
    "MyFunctions.js ");

    The .js file is in the same directory as the page. and has only one
    function:

    function SayHello()
    {
    alert("Hello")
    }

    I added the function call on the code behind page load

    btnLast.Attribu tes.Add("onclic k", "SayHello() ");

    is there supposed to be some directive in the .js file?

    Any ideas? This is driving me nuts!!!

    Thanks.

    Matthew Wells
    Matthew.Wells@F irstByte.net


  • Mark Rae [MVP]

    #2
    Re: Can't get javascript file to work...

    "Matthew Wells" <Matthew.Wells@ FirstByte.netwr ote in message
    news:osudnaRTUZ-3OVTanZ2dnUVZ_j 2dnZ2d@comcast. com...
    Any ideas? This is driving me nuts!!!
    First things first...

    1) Does it work if you reference the file directly? E.g.

    <head>
    <script type="text/javascript" src="MyFunction s.js"></script>
    </head>

    2) JavaScript, generally speaking, requires semi-colons at the end of each
    statement e.g.

    function SayHello()
    {
    alert("Hello");
    }

    and

    btnLast.Attribu tes.Add("onclic k", "SayHello() ;");

    Does that help...?

    3) Have you inadvertently turned JavaScript off in your browser...?


    --
    Mark Rae
    ASP.NET MVP


    Comment

    • Matthew Wells

      #3
      Re: Can't get javascript file to work...

      I did have semicolons - I didn't type it right here. I know the
      ..attributes.ad d and the function itself work because it works when the
      function is in the aspx page. It just doen't work when I put it in the
      file. I also did try to reference it direclty.

      Is there something needed at the top of the .js file?
      Do I use RegisterClientS criptInclude or RegisterClientS criptBlock?

      Also, and I know this probably doesn't matter, but... I'm using Visual
      Studio 2005. I added the page using Add New Item - JScript File (There is
      no "JavaScript " file choice.) This shouldn't make a difference because it's
      just a text file with a .js extension, right? (he asked hopefully).

      Thanks.


      "Mark Rae [MVP]" <mark@markNOSPA Mrae.netwrote in message
      news:%236Hc0%23 8eIHA.4120@TK2M SFTNGP06.phx.gb l...
      "Matthew Wells" <Matthew.Wells@ FirstByte.netwr ote in message
      news:osudnaRTUZ-3OVTanZ2dnUVZ_j 2dnZ2d@comcast. com...
      >
      >Any ideas? This is driving me nuts!!!
      >
      First things first...
      >
      1) Does it work if you reference the file directly? E.g.
      >
      <head>
      <script type="text/javascript" src="MyFunction s.js"></script>
      </head>
      >
      2) JavaScript, generally speaking, requires semi-colons at the end of each
      statement e.g.
      >
      function SayHello()
      {
      alert("Hello");
      }
      >
      and
      >
      btnLast.Attribu tes.Add("onclic k", "SayHello() ;");
      >
      Does that help...?
      >
      3) Have you inadvertently turned JavaScript off in your browser...?
      >
      >
      --
      Mark Rae
      ASP.NET MVP
      http://www.markrae.net

      Comment

      Working...