473,326 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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.ClientScript.RegisterClientScriptBlock(this.G etType(), "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
Ma***********@FirstByte.net
Mar 1 '08 #1
2 1555
"Matthew Wells" <Ma***********@FirstByte.netwrote in message
news:os******************************@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="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

Mar 1 '08 #2
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]" <ma**@markNOSPAMrae.netwrote in message
news:%2******************@TK2MSFTNGP06.phx.gbl...
"Matthew Wells" <Ma***********@FirstByte.netwrote in message
news:os******************************@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="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

Mar 1 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Noneley | last post by:
Thank you for reading. I am not a programmer, I can just about cobble things together using code examples, so please be gentle! - I will have an application open, such as Excel or Word. - I...
10
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How can I access the client-side filesystem?...
2
by: Altman | last post by:
I have created an ascx control and I am calling registerclientscriptblock. The path to the js file is relative to the aspx page and not the ascx file. The function runs fine in IE7 but in...
9
by: Mahernoz | last post by:
Hello Friends, The JavaScript File exmplmenu_var.js contains the code... (for the sake of brevity i am showing only that code which needs to be changed) I am actually developing a menu using...
20
RMWChaos
by: RMWChaos | last post by:
Currently testing in: WinVista / IE7 I have been working on getting xmlhttprequest going for weeks now. I have finally gotten a semi-working script going. Pulling up text or xml files works great...
1
by: wenijah | last post by:
Hi everyone! First thank you for reading this post and yes, you probably already see that kind of topic title somewhere but the problem I've got today might be different than the 100 topics I've...
9
by: Matthew Wells | last post by:
OK, I've narrowed down the problem. This works when in the aspx page <script type="text/javascript" > function btnFirst_Click() { alert("Hello");...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.