Simple Javascript in ASP.NET

B

Brian Piotrowski

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.
 
B

bruce barker \(sqlwork.com\)

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)
 
L

Laurent Bugnion

Hi,
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
 

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

Top