Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Calling client side Javascript from a server side button

Reply
Thread Tools

Calling client side Javascript from a server side button

 
 
=?Utf-8?B?Qw==?=
Guest
Posts: n/a
 
      01-16-2004
Hi,

I have a server side asp.net button on a web page.

On clicking the button I want to call some Javascript.

Can I not simply do a onclick="MyJavascript();" or is it necessary that I add the onclick as an attribute in my codebehind?

Thanks,
C.
 
Reply With Quote
 
 
 
 
Hermit Dave
Guest
Posts: n/a
 
      01-16-2004
well if you want to bind server side control with client side script.. and
if that object has a server side event as well... then your aspx should look
like this
<asp:Button id=Button1 onclick="javascript:clientsideclick();"
onServerClick="serverEventHandler">

the preferred way is to use
Page.RegisterClientScriptBlock to register any custom javascript functions

you can hardcode the onclick and onserverclick
but again the preferred way is to use
Button1.Attributes.Add("onClick", "clientSideClick();");
Button1.Attributes.Add("onServerClick", "serverEventHandler");

hope this helps.. btw.. if you dont have server event you dont need to add
onServerClient attribute

--

Regards,

HD
"C" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I have a server side asp.net button on a web page.
>
> On clicking the button I want to call some Javascript.
>
> Can I not simply do a onclick="MyJavascript();" or is it necessary that I

add the onclick as an attribute in my codebehind?
>
> Thanks,
> C.



 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Button disabled and re-enabled in client side not firing server-side click event. =?Utf-8?B?QmluIFNvbmcsIE1DUA==?= ASP .Net 2 05-27-2008 09:57 AM
Making the same button do client side javascript and server side vbscript? COHENMARVIN ASP .Net 2 10-20-2005 01:13 AM
Calling a client side script from server side. =?Utf-8?B?RHVzdGluIElJLg==?= ASP .Net 3 08-16-2004 10:10 PM
Server Side button calling page_load before calling it's own click event. Ryan Ternier ASP .Net 4 07-29-2004 01:06 PM
button evet ---- server side - client side ??? yaya coco ASP .Net 1 07-04-2003 10:58 PM



Advertisments