Groups | Blog | Home
all groups > asp.net webcontrols > november 2007 >

asp.net webcontrols : Calling JavaScript Function from ASP.Net Button


WhiskeyRomeo
11/15/2007 6:20:00 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.

WhiskeyRomeo
11/17/2007 8:07:01 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

[quoted text, click to view]
Riki
11/17/2007 12:56:04 PM
[quoted text, click to view]

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

--

Riki

Riki
11/17/2007 7:50:44 PM
[quoted text, click to view]

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

[quoted text, click to view]

AddThis Social Bookmark Button