Javastript file still won't work...

M

Matthew Wells

Hello. This is a repost because nothing has worked so far.

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?

I've also tried just directly referencing the file in the aspx file with:
<script type="text/javascript" src="MyFunctions.js"></script>
Still no luck.

Any ideas? This is STILL driving me nuts!!!

Thanks.

Matthew Wells
(e-mail address removed)
 
M

Michael Nemtsev [MVP]

Hello Matthew,

Have u tried to use ClientScriptManager.RegisterStartupScript ?

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


MW> Hello. This is a repost because nothing has worked so far.
MW>
MW> I thought this was supposed to be simple. I'm trying to use a .js
MW> file for my javascript functions. I'm testing by only using one
MW> function The function works when it's at the top of my aspx file.
MW>
MW> The file is called "MyFunctions.js" which was imported on the page
MW> load event of the code-behind form with:
MW> Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
MW> "MyFuncs", "MyFunctions.js", true); - I've used this with both true
MW> and false and with adding script tags myself in the .js file.
MW>
MW> I've also tried
MW> Page.ClientScript.RegisterClientScriptInclude(this.GetType(),
MW> "MyFuncs", "MyFunctions.js");
MW>
MW> The .js file is in the same directory as the page. and has only one
MW> function:
MW>
MW> function SayHello()
MW> {
MW> alert("Hello");
MW> }
MW> I added the function call on the code behind page load
MW>
MW> btnLast.Attributes.Add("onclick", "SayHello()");
MW>
MW> is there supposed to be some directive in the .js file?
MW>
MW> I've also tried just directly referencing the file in the aspx file
MW> with:
MW> <script type="text/javascript" src="MyFunctions.js"></script>
MW> Still no luck.
MW> Any ideas? This is STILL driving me nuts!!!
MW>
MW> Thanks.
MW>
MW> Matthew Wells
MW> (e-mail address removed)
 
M

Matthew Wells

I'm trying it, but I can't seem to get the syntax down. Can you show me an
example?

Thanks.

Matthew Wells
(e-mail address removed)
 

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