How to Call functions written in javascript file ?

G

Guest

I want to group all the javascript functions into a file named MiscFunc.js in
a asp.net project.
========================================
e.g. In MiscFunc.js
function dummyFunc(var1, var2)
{
alert(var1 + var2);
}
========================================

This javascript function will be called when a asp button is clicked.
========================================
butSubmit.Attributes.Add("onclick", "dummyFunc('abc', 'dec'); ")
========================================

and i've already added statement in the following in the <head> block of HTML
========================================
<script language="javascript" src="MiscFunc.js"></script>
========================================

Of coz, the code i stated above does not work anyway.
Do anyone of you knows how to make it work ?
thx
 
R

rohit pachnanda

hi,
i hope it will work follow it....
in code behind:
Protected WithEvents but1 As
System.Web.UI.WebControls.Button
then,
on page_load add
butsubmit.Attributes.Add("onclick", "dummyFunc
('abc', 'dec')")
bye for now
rohit pachnanda
software engineer
 
G

Guest

the code --->
*** butSubmit.Attributes.Add("onclick", "dummyFunc('abc', 'dec'); ") ***
doesn't work

it's no proble if that change to
butSubmit.Attributes.Add("onclick", "alert('dummyMsg'); ")

but i really want to how can i called the functions written in external
javascript file'
 
R

rohit

In code behind...
Protected WithEvents butsubmit As
System.Web.UI.WebControls.button
In page_load...
butSubmit.Attributes.Add("onclick", "dummyFunc
('abc', 'dec') ")
remove ;
 
G

Guest

did u try that ?
it doesn't work for me anyway.

rohit said:
In code behind...
Protected WithEvents butsubmit As
System.Web.UI.WebControls.button
In page_load...
butSubmit.Attributes.Add("onclick", "dummyFunc
('abc', 'dec') ")
remove ;
 
G

Guest

I mean ... juz part of that work.
maybe i made a worse example out .....
thx guys ...
 
E

Eliyahu Goldin

Do you get any error message? The code looks good to me. Make sure your file
is in the same directory with the page. There could be other errors in the
script file that prevent calling your function. Try to call it just from
client code, for example from body's onload event.

Eliyahu
 
R

rohit

include file .js in same folder ok
i tried it on code behind in page_load
remove ;
it`s working it`s giving alert "abcdec"
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top