How to Call functions written in javascript file ?

Discussion in 'ASP .Net' started by =?Utf-8?B?TWF2ZXJpY2s=?=, Jan 20, 2005.

  1. 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
     
    =?Utf-8?B?TWF2ZXJpY2s=?=, Jan 20, 2005
    #1
    1. Advertising

  2. What exactly doesn't work?

    Eliyahu

    "Maverick" <> wrote in message
    news:...
    > 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
     
    Eliyahu Goldin, Jan 20, 2005
    #2
    1. Advertising

  3. 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

    >-----Original Message-----
    >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
    >.
    >
     
    rohit pachnanda, Jan 20, 2005
    #3
  4. 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'

    "Eliyahu Goldin" wrote:

    > What exactly doesn't work?
    >
    > Eliyahu
    >
    > "Maverick" <> wrote in message
    > news:...
    > > 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

    >
    >
    >
     
    =?Utf-8?B?TWF2ZXJpY2s=?=, Jan 20, 2005
    #4
  5. =?Utf-8?B?TWF2ZXJpY2s=?=

    rohit Guest

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

    >-----Original Message-----
    >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'
    >
    >"Eliyahu Goldin" wrote:
    >
    >> What exactly doesn't work?
    >>
    >> Eliyahu
    >>
    >> "Maverick" <> wrote

    in message
    >> news:040727BC-1148-4EC7-96B2-

    ...
    >> > 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

    >>
    >>
    >>

    >.
    >
     
    rohit, Jan 20, 2005
    #5
  6. did u try that ?
    it doesn't work for me anyway.

    "rohit" wrote:

    > In code behind...
    > Protected WithEvents butsubmit As
    > System.Web.UI.WebControls.button
    > In page_load...
    > butSubmit.Attributes.Add("onclick", "dummyFunc
    > ('abc', 'dec') ")
    > remove ;
    >
    > >-----Original Message-----
    > >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'
    > >
    > >"Eliyahu Goldin" wrote:
    > >
    > >> What exactly doesn't work?
    > >>
    > >> Eliyahu
    > >>
    > >> "Maverick" <> wrote

    > in message
    > >> news:040727BC-1148-4EC7-96B2-

    > ...
    > >> > 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
    > >>
    > >>
    > >>

    > >.
    > >

    >
     
    =?Utf-8?B?TWF2ZXJpY2s=?=, Jan 20, 2005
    #6
  7. I mean ... juz part of that work.
    maybe i made a worse example out .....
    thx guys ...

    "Maverick" wrote:

    > did u try that ?
    > it doesn't work for me anyway.
    >
    > "rohit" wrote:
    >
    > > In code behind...
    > > Protected WithEvents butsubmit As
    > > System.Web.UI.WebControls.button
    > > In page_load...
    > > butSubmit.Attributes.Add("onclick", "dummyFunc
    > > ('abc', 'dec') ")
    > > remove ;
    > >
    > > >-----Original Message-----
    > > >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'
    > > >
    > > >"Eliyahu Goldin" wrote:
    > > >
    > > >> What exactly doesn't work?
    > > >>
    > > >> Eliyahu
    > > >>
    > > >> "Maverick" <> wrote

    > > in message
    > > >> news:040727BC-1148-4EC7-96B2-

    > > ...
    > > >> > 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
    > > >>
    > > >>
    > > >>
    > > >.
    > > >

    > >
     
    =?Utf-8?B?TWF2ZXJpY2s=?=, Jan 20, 2005
    #7
  8. 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

    "Maverick" <> wrote in message
    news:...
    > 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'
    >
    > "Eliyahu Goldin" wrote:
    >
    > > What exactly doesn't work?
    > >
    > > Eliyahu
    > >
    > > "Maverick" <> wrote in message
    > > news:...
    > > > 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

    > >
    > >
    > >
     
    Eliyahu Goldin, Jan 20, 2005
    #8
  9. =?Utf-8?B?TWF2ZXJpY2s=?=

    rohit Guest

    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"

    >-----Original Message-----
    >did u try that ?
    >it doesn't work for me anyway.
    >
    >"rohit" wrote:
    >
    >> In code behind...
    >> Protected WithEvents butsubmit As
    >> System.Web.UI.WebControls.button
    >> In page_load...
    >> butSubmit.Attributes.Add("onclick", "dummyFunc
    >> ('abc', 'dec') ")
    >> remove ;
    >>
    >> >-----Original Message-----
    >> >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'
    >> >
    >> >"Eliyahu Goldin" wrote:
    >> >
    >> >> What exactly doesn't work?
    >> >>
    >> >> Eliyahu
    >> >>
    >> >> "Maverick" <>

    wrote
    >> in message
    >> >> news:040727BC-1148-4EC7-96B2-

    >> ...
    >> >> > 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
    >> >>
    >> >>
    >> >>
    >> >.
    >> >

    >>

    >.
    >
     
    rohit, Jan 20, 2005
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve C. Orr, MCSD
    Replies:
    1
    Views:
    563
    reaway lee
    Aug 24, 2003
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,611
    Victor Bazarov
    Jun 21, 2004
  3. beginner
    Replies:
    7
    Views:
    554
    Alex Martelli
    Aug 19, 2007
  4. KaiWen
    Replies:
    102
    Views:
    2,738
    Jorgen Grahn
    Sep 15, 2011
  5. Zhiguo
    Replies:
    1
    Views:
    109
    Michael Haufe (\TNO\)
    Dec 10, 2009
Loading...

Share This Page