Calling JavaScript Function from ASP.Net Button

W

WhiskeyRomeo

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
 
R

Riki

WhiskeyRomeo said:
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).
 
W

WhiskeyRomeo

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
 
R

Riki

WhiskeyRomeo said:
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
 

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

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top