PC Review


Reply
Thread Tools Rate Thread

Can't get javascript file to work...

 
 
Matthew Wells
Guest
Posts: n/a
 
      1st Mar 2008
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.ClientScript.RegisterClientScriptBlock(this.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.ClientScript.RegisterClientScriptInclude(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.Attributes.Add("onclick", "SayHello()");

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

Any ideas? This is driving me nuts!!!

Thanks.

Matthew Wells
(E-Mail Removed)


 
Reply With Quote
 
 
 
 
Mark Rae [MVP]
Guest
Posts: n/a
 
      1st Mar 2008
"Matthew Wells" <(E-Mail Removed)> wrote in message
newssudnaRTUZ-(E-Mail Removed)...

> 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="MyFunctions.js"></script>
</head>

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

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

and

btnLast.Attributes.Add("onclick", "SayHello();");

Does that help...?

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


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

 
Reply With Quote
 
Matthew Wells
Guest
Posts: n/a
 
      1st Mar 2008
I did have semicolons - I didn't type it right here. I know the
..attributes.add 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 RegisterClientScriptInclude or RegisterClientScriptBlock?

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]" <(E-Mail Removed)> wrote in message
news:%236Hc0%(E-Mail Removed)...
> "Matthew Wells" <(E-Mail Removed)> wrote in message
> newssudnaRTUZ-(E-Mail Removed)...
>
>> 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="MyFunctions.js"></script>
> </head>
>
> 2) JavaScript, generally speaking, requires semi-colons at the end of each
> statement e.g.
>
> function SayHello()
> {
> alert("Hello");
> }
>
> and
>
> btnLast.Attributes.Add("onclick", "SayHello();");
>
> Does that help...?
>
> 3) Have you inadvertently turned JavaScript off in your browser...?
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: javascript file won't work with .cs file... bruce barker Microsoft ASP .NET 0 9th May 2008 05:55 AM
Javascript menu - can't get to work in aspx file trint Microsoft ASP .NET 0 4th Dec 2006 02:45 PM
javascript won't work on IE7 tong Windows XP Internet Explorer 1 7th Nov 2006 10:41 PM
Javascript Menu won't work as an include file Don Pearsall Microsoft Frontpage 7 4th Nov 2004 09:07 PM
javascript don't work Jim Madsen Windows XP Internet Explorer 3 14th Feb 2004 01:43 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:35 AM.