how to add client-side event handler to a server-side control?

how to add client-side event handler to a server-side control?

Post by jliu » Fri, 14 Mar 2003 07:54:53



I have a server-side button button, say, "cmdRemove". before it calls the
doPost function that will send the request to the server, I want it run the
client script first. say, pop up a confirm box to ask the user "are you
sure?", which can prevent our server from disturbing too frequently.
if I can control everything in the generated HTML page, I can simply write
onclick="clientFunc() && __doPostBack('cmdRemove','')"
but the problem is how to tell the .net to do so?
thanks a lot!
 
 
 

how to add client-side event handler to a server-side control?

Post by Sandes » Fri, 14 Mar 2003 08:11:22


In the server side inside Page_Load function just add an
attribute to the button like this.
cmdRemove.Attributes.Add("onclick","javascript:Validate
();")

In the javascript function if the user clicks on cancel in
the confirm dialog just set window.event.returnValue=false;

Quote:>-----Original Message-----
>I have a server-side button button, say, "cmdRemove".
before it calls the
>doPost function that will send the request to the server,
I want it run the
>client script first. say, pop up a confirm box to ask the
user "are you
>sure?", which can prevent our server from disturbing too
frequently.
>if I can control everything in the generated HTML page, I
can simply write
>onclick="clientFunc() && __doPostBack('cmdRemove','')"
>but the problem is how to tell the .net to do so?
>thanks a lot!

>.


 
 
 

how to add client-side event handler to a server-side control?

Post by jliu » Sat, 15 Mar 2003 08:51:26


thanks!
I found another way: just add two amphasands at the end of the event
handler. so most work can be done by just clicking the mouse  in the IDE. :)

a demo code is like following:


Inherits="dediadm.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
  <title>demo</title>
  <meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
  <meta content="C#" name="CODE_LANGUAGE">
  <meta content="JavaScript" name="vs_defaultClientScript">
  <meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
  <script language="javascript" id="clientEventHandlersJS">
<!--

function cmdRemove_onclick() {
 return confirm ("are you sure?");

Quote:}

//-->
  </script>
</HEAD>
 <body>
  <form id="Form1" method="post" runat="server">
   <INPUT language="javascript" id="cmdRemove" disabled
onclick="cmdRemove_onclick()&amp;&amp;" type="button" value="Remove"
runat="server"></TD>
  </form>
 </body>
</HTML>
----- Original Message -----

Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Wednesday, March 12, 2003 6:11 PM
Subject: how to add client-side event handler to a server-side control?

> In the server side inside Page_Load function just add an
> attribute to the button like this.
> cmdRemove.Attributes.Add("onclick","javascript:Validate
> ();")

> In the javascript function if the user clicks on cancel in
> the confirm dialog just set window.event.returnValue=false;

> >-----Original Message-----
> >I have a server-side button button, say, "cmdRemove".
> before it calls the
> >doPost function that will send the request to the server,
> I want it run the
> >client script first. say, pop up a confirm box to ask the
> user "are you
> >sure?", which can prevent our server from disturbing too
> frequently.
> >if I can control everything in the generated HTML page, I
> can simply write
> >onclick="clientFunc() && __doPostBack('cmdRemove','')"
> >but the problem is how to tell the .net to do so?
> >thanks a lot!

> >.