469,632 Members | 1,639 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,632 developers. It's quick & easy.

javascript file won't work with .cs file...

Hello. I'm reposting this because my prioe post's subject line was
incorrect.

I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with all
the updates. I have an aspx page with javascript that works fine until I
try to separate the script into a .js file. I've found that only the script
that is called from events set in the aspx.cs file don't work. I eliminated
all script except two functions. One is used with the .cs file and the
other one is not.

First, here's the functino used with the .cs file:
if (!this.IsPostBack)
{

btnFirst.OnClientClick = "return btnFirst_Click()";

}
.... the javascript function is...
function btnFirst_Click()

{

alert("This is btnFirst_Click"):

return false;

}

Now the second javascript function is only

function ShowAlert()
{
alert("This is ShowAlert");
return false;
}

This function is called from another button - button1 - from the
OnClientClick event which I set in the property page..

When I have all the javascript in the aspx page, it all wokrs, but when I
move it to a .js file, the first function doesn't work, but the second one
does.

I don't want to add all my javascript in rhe .cs file because that would
expose all my code - that's why I'm teying to put it in a .js file.

How can I make all the code work using both methods?

Thanks...

--
Matthew.Wells
Ma***********@FirstByte.net
Jun 27 '08 #1
2 2509
you don't give enough info to know what you are doing wrong. there is no
difference between inline script or included script.

try using firefox to debug the script, you must have a syntax error.

-- bruce (sqlwork.com)
Matthew Wells wrote:
Hello. I'm reposting this because my prioe post's subject line was
incorrect.

I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with all
the updates. I have an aspx page with javascript that works fine until I
try to separate the script into a .js file. I've found that only the script
that is called from events set in the aspx.cs file don't work. I eliminated
all script except two functions. One is used with the .cs file and the
other one is not.

First, here's the functino used with the .cs file:
if (!this.IsPostBack)
{

btnFirst.OnClientClick = "return btnFirst_Click()";

}
... the javascript function is...
function btnFirst_Click()

{

alert("This is btnFirst_Click"):

return false;

}

Now the second javascript function is only

function ShowAlert()
{
alert("This is ShowAlert");
return false;
}

This function is called from another button - button1 - from the
OnClientClick event which I set in the property page..

When I have all the javascript in the aspx page, it all wokrs, but when I
move it to a .js file, the first function doesn't work, but the second one
does.

I don't want to add all my javascript in rhe .cs file because that would
expose all my code - that's why I'm teying to put it in a .js file.

How can I make all the code work using both methods?

Thanks...
Jun 27 '08 #2
There is no syntax error. I copy and paste the code in the aspx page and it
works fine. If there were a syntax error, nothing would work. I know I"m
using the included script properly because the second function works. The
problem I think is in the timing of when the script is added and the event
is set to the button.

From the aspx.cs OnLoad event...

btnFirst.OnClientClick = "return btnFirst_Click()"

the javascript function for that event is

function btnFirst_Click()
{
alert("This is btnFirst_Click");
return false;
}

This doesn't work, but this does

function Button1_Click()
{
alert("This is ShowAlert");
return false;
}

In the property page for Button1, I manually put "ShowAlert()" in the
OnclientClick event - it works that way.

I even switched the functions and still the one that is bound in the aspx.cs
code won't work.

Does someone else have a clue?

"bruce barker" <no****@nospam.comwrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
you don't give enough info to know what you are doing wrong. there is no
difference between inline script or included script.

try using firefox to debug the script, you must have a syntax error.

-- bruce (sqlwork.com)
Matthew Wells wrote:
>Hello. I'm reposting this because my prioe post's subject line was
incorrect.

I'm developing an asp.net 2.0 project using VS 2005 on XP sp2 with
all
the updates. I have an aspx page with javascript that works fine until I
try to separate the script into a .js file. I've found that only the
script
that is called from events set in the aspx.cs file don't work. I
eliminated
all script except two functions. One is used with the .cs file and the
other one is not.

First, here's the functino used with the .cs file:
if (!this.IsPostBack)
{

btnFirst.OnClientClick = "return btnFirst_Click()";

}
... the javascript function is...
function btnFirst_Click()

{

alert("This is btnFirst_Click"):

return false;

}

Now the second javascript function is only

function ShowAlert()
{
alert("This is ShowAlert");
return false;
}

This function is called from another button - button1 - from the
OnClientClick event which I set in the property page..

When I have all the javascript in the aspx page, it all wokrs, but when I
move it to a .js file, the first function doesn't work, but the second
one
does.

I don't want to add all my javascript in rhe .cs file because that would
expose all my code - that's why I'm teying to put it in a .js file.

How can I make all the code work using both methods?

Thanks...

Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.