Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / Web Controls / November 2007

Tip: Looking for answers? Try searching our database.

Calling JavaScript Function from ASP.Net Button

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WhiskeyRomeo - 16 Nov 2007 02:20 GMT
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
Riki - 17 Nov 2007 11:56 GMT
> Is it not possible to call a JS function from an ASP.Net button.
>
[quoted text clipped - 11 lines]
>
> WR

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

Signature

Riki

WhiskeyRomeo - 17 Nov 2007 16:07 GMT
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

> > Is it not possible to call a JS function from an ASP.Net button.
> >
[quoted text clipped - 13 lines]
>
> Use OnClientClick instead of OnClick (ASP.NET 2.0 or higher).
Riki - 17 Nov 2007 18:50 GMT
> 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

Signature

Riki

>>> Is it not possible to call a JS function from an ASP.Net button.
>>>
[quoted text clipped - 17 lines]
>>
>> Riki

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.