HighTechTalks DotNet Forums  

Calling JavaScript Function from ASP.Net Button

ASP.net Web Controls microsoft.public.dotnet.framework.aspnet.webcontrols


Discuss Calling JavaScript Function from ASP.Net Button in the ASP.net Web Controls forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
WhiskeyRomeo
 
Posts: n/a

Default Calling JavaScript Function from ASP.Net Button - 11-15-2007 , 08:20 PM






Is it not possible to call a JS function from an ASP.Net button.

In the HTML I assign the onClick="JS_Function()"

But when page is rendered I get the error:

JS_Function() is not a member of MyPage.aspx.

It appears the onClick is the same as the Click event, because all the
examples I saw show VB.Net, C# or JScript sever side code.

I am try to use a webimage button because it give me the look I want to call
a client side JavaScript.

WR

Reply With Quote
  #2  
Old   
Riki
 
Posts: n/a

Default Re: Calling JavaScript Function from ASP.Net Button - 11-17-2007 , 05:56 AM






WhiskeyRomeo wrote:
Quote:
Is it not possible to call a JS function from an ASP.Net button.

In the HTML I assign the onClick="JS_Function()"

But when page is rendered I get the error:

JS_Function() is not a member of MyPage.aspx.

It appears the onClick is the same as the Click event, because all the
examples I saw show VB.Net, C# or JScript sever side code.

I am try to use a webimage button because it give me the look I want
to call a client side JavaScript.

WR
Use OnClientClick instead of OnClick (ASP.NET 2.0 or higher).

--

Riki




Reply With Quote
  #3  
Old   
WhiskeyRomeo
 
Posts: n/a

Default Re: Calling JavaScript Function from ASP.Net Button - 11-17-2007 , 10:07 AM



Sorry, I forgot to mention this is 1.1 application. We are not quite ready
to upgradie it to 2.0. Is there any solution for 1.1?

WR

"Riki" wrote:

Quote:
WhiskeyRomeo wrote:
Is it not possible to call a JS function from an ASP.Net button.

In the HTML I assign the onClick="JS_Function()"

But when page is rendered I get the error:

JS_Function() is not a member of MyPage.aspx.

It appears the onClick is the same as the Click event, because all the
examples I saw show VB.Net, C# or JScript sever side code.

I am try to use a webimage button because it give me the look I want
to call a client side JavaScript.

WR

Use OnClientClick instead of OnClick (ASP.NET 2.0 or higher).

--

Riki




Reply With Quote
  #4  
Old   
Riki
 
Posts: n/a

Default Re: Calling JavaScript Function from ASP.Net Button - 11-17-2007 , 12:50 PM



WhiskeyRomeo wrote:
Quote:
Sorry, I forgot to mention this is 1.1 application. We are not quite
ready to upgradie it to 2.0. Is there any solution for 1.1?

WR
Yes, you have to add the clientside onclick programmatically, like this
(in Page_Load)
If Not Ispostback Then
myButton.Attributes.Add("onclick","JS_Function()")
End If

--

Riki

Quote:
"Riki" wrote:

WhiskeyRomeo wrote:
Is it not possible to call a JS function from an ASP.Net button.

In the HTML I assign the onClick="JS_Function()"

But when page is rendered I get the error:

JS_Function() is not a member of MyPage.aspx.

It appears the onClick is the same as the Click event, because all
the examples I saw show VB.Net, C# or JScript sever side code.

I am try to use a webimage button because it give me the look I want
to call a client side JavaScript.

WR

Use OnClientClick instead of OnClick (ASP.NET 2.0 or higher).

--

Riki



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.