Simple Javascript in ASP.NET

Discussion in 'ASP .Net' started by Brian Piotrowski, Sep 14, 2006.

  1. Hi All,

    After many years of ASP 3.0, I am finally taking the plunge and moving to
    ASP.NET. I'm going through a few tutorials, and I'm wondering if someone
    can answer me a question on adding a simple Javascipt to an ASP.NET page.

    In my old ASP code, I used an #include function to add a javascript to my
    webpage. I've been reading that it is not recommended to use this technique
    in ASP.NET. The javascript I would like to add is pretty basic - it's just
    a script to fade between images in the header.

    Can someone tell me what I could do as an alternate to the #include function
    under ASP.NET? I'd really hate to have to post the javascipt in my master
    file if I can avoid it.

    So before, I had this:

    <head>
    <!--#include file ="stylesheet.css"-->
    <!--#include file ="fadescript.js"-->
    </head>

    I figured out how to show the stylesheet in the page. My question is how do
    I get the fadescript.js into my ASP.NET pages?

    Thanks!

    Brian.
     
    Brian Piotrowski, Sep 14, 2006
    #1
    1. Advertising

  2. Brian Piotrowski

    Mike Lowery Guest

    Have you tried:

    <script type="text/javascript" SRC="filename.js" />

    "Brian Piotrowski" <> wrote in message
    news:%...
    > Hi All,
    >
    > After many years of ASP 3.0, I am finally taking the plunge and moving to
    > ASP.NET. I'm going through a few tutorials, and I'm wondering if someone can
    > answer me a question on adding a simple Javascipt to an ASP.NET page.
    >
    > In my old ASP code, I used an #include function to add a javascript to my
    > webpage. I've been reading that it is not recommended to use this technique
    > in ASP.NET. The javascript I would like to add is pretty basic - it's just a
    > script to fade between images in the header.
    >
    > Can someone tell me what I could do as an alternate to the #include function
    > under ASP.NET? I'd really hate to have to post the javascipt in my master
    > file if I can avoid it.
    >
    > So before, I had this:
    >
    > <head>
    > <!--#include file ="stylesheet.css"-->
    > <!--#include file ="fadescript.js"-->
    > </head>
    >
    > I figured out how to show the stylesheet in the page. My question is how do I
    > get the fadescript.js into my ASP.NET pages?
    >
    > Thanks!
    >
    > Brian.
    >
     
    Mike Lowery, Sep 14, 2006
    #2
    1. Advertising

  3. It is a bit different. Theres a really good tutorial here for you courtesy
    of Microsoft on how to work with Javascript.
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/JAVAwASP2.asp

    Regards

    John Timney (MVP)
    VISIT MY WEBSITE:
    http://www.johntimney.com


    "Brian Piotrowski" <> wrote in message
    news:%...
    > Hi All,
    >
    > After many years of ASP 3.0, I am finally taking the plunge and moving to
    > ASP.NET. I'm going through a few tutorials, and I'm wondering if someone
    > can answer me a question on adding a simple Javascipt to an ASP.NET page.
    >
    > In my old ASP code, I used an #include function to add a javascript to my
    > webpage. I've been reading that it is not recommended to use this
    > technique in ASP.NET. The javascript I would like to add is pretty
    > basic - it's just a script to fade between images in the header.
    >
    > Can someone tell me what I could do as an alternate to the #include
    > function under ASP.NET? I'd really hate to have to post the javascipt in
    > my master file if I can avoid it.
    >
    > So before, I had this:
    >
    > <head>
    > <!--#include file ="stylesheet.css"-->
    > <!--#include file ="fadescript.js"-->
    > </head>
    >
    > I figured out how to show the stylesheet in the page. My question is how
    > do I get the fadescript.js into my ASP.NET pages?
    >
    > Thanks!
    >
    > Brian.
    >
     
    John Timney \(MVP\), Sep 14, 2006
    #3
  4. instead of a server include use a javascript ref:

    <head>
    <script src="fadescript.js" />
    </head>

    be sure to remove script tags from the js file

    -- bruce (sqlwork.com)


    "Brian Piotrowski" <> wrote in message
    news:%...
    > Hi All,
    >
    > After many years of ASP 3.0, I am finally taking the plunge and moving to
    > ASP.NET. I'm going through a few tutorials, and I'm wondering if someone
    > can answer me a question on adding a simple Javascipt to an ASP.NET page.
    >
    > In my old ASP code, I used an #include function to add a javascript to my
    > webpage. I've been reading that it is not recommended to use this
    > technique in ASP.NET. The javascript I would like to add is pretty
    > basic - it's just a script to fade between images in the header.
    >
    > Can someone tell me what I could do as an alternate to the #include
    > function under ASP.NET? I'd really hate to have to post the javascipt in
    > my master file if I can avoid it.
    >
    > So before, I had this:
    >
    > <head>
    > <!--#include file ="stylesheet.css"-->
    > <!--#include file ="fadescript.js"-->
    > </head>
    >
    > I figured out how to show the stylesheet in the page. My question is how
    > do I get the fadescript.js into my ASP.NET pages?
    >
    > Thanks!
    >
    > Brian.
    >
     
    bruce barker \(sqlwork.com\), Sep 14, 2006
    #4
  5. Hi,

    bruce barker (sqlwork.com) wrote:
    > instead of a server include use a javascript ref:
    >
    > <head>
    > <script src="fadescript.js" />
    > </head>
    >
    > be sure to remove script tags from the js file
    >
    > -- bruce (sqlwork.com)


    Note that depending on the DOCTYPE, having a script tag without end tag
    can cause problems. You should also set the type to avoid errors. I
    recommend using the <script type="text/javascript" src="..."></script> form.

    HTH,
    Laurent
    --
    Laurent Bugnion, GalaSoft
    Software engineering: http://www.galasoft-LB.ch
    PhotoAlbum: http://www.galasoft-LB.ch/pictures
    Support children in Calcutta: http://www.calcutta-espoir.ch
     
    Laurent Bugnion, Sep 15, 2006
    #5
    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. David Virgil Hobbs
    Replies:
    0
    Views:
    542
    David Virgil Hobbs
    Jan 6, 2004
  2. Davisro
    Replies:
    4
    Views:
    811
    Bruno Sirianni
    Apr 10, 2004
  3. Dave E
    Replies:
    7
    Views:
    771
    Josh Twist
    Jan 11, 2006
  4. Martin Rakhmanov
    Replies:
    3
    Views:
    1,172
    Martin Rakhmanov
    Feb 26, 2006
  5. Dave E
    Replies:
    7
    Views:
    223
    Josh Twist
    Jan 11, 2006
Loading...

Share This Page