Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

HtmlButton.ServerClick Event

Occurs when the user clicks an HtmlButton control on the client Web page.

[Visual Basic]
Public Event ServerClick As EventHandler
[C#]
public event EventHandler ServerClick;
[C++]
public: __event EventHandler* ServerClick;

[JScript] In JScript, you can handle the events defined by a class, but you cannot define your own.

Event Data

The event handler receives an argument of type EventArgs.

Remarks

The ServerClick event is raised when the HtmlButton control is clicked. This server event causes a roundtrip to occur from the client to the server and back. It is deliberately different from the client-side OnClick event. In the event that a conflict exists between code run with a ServerClick event and code run by a client-side OnClick event, the server-side event instructions will override the client-side code.

For more information about handling events, see Consuming Events.

Example

[Visual Basic, C#, JScript] The following example demonstrates how to declaratively specify and code an event handler for the ServerClick event. When the HtmlButton control is clicked, the value entered in the text box displayed.

[Visual Basic] 
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
    <script language="VB" runat=server>
       Sub FancyBtn_Click(Source As Object, E as EventArgs)
          Message.InnerHtml = "Your name is: " & Name.Value
       End Sub
    </script>
  
    <body>
          <form method=post runat=server>
  
            <h3> Enter Name: <input id="Name" type=text size=40 runat=server>
            </h3>
  
             <button OnServerClick=" FancyBtn_Click" runat=server>
               <b><I> I'm a fancy HTML 4.0 button </I> </b> 
             </button>
  
                       
           <h1>
             <span id="Message" runat=server></span>
           </h1>
  
          </form>
       </body>
 </html>
    

[JScript] 
<%@ Page Language="JScript" AutoEventWireup="True" %>

<html>
    <script language="jscript" runat=server>
       function FancyBtn_Click(Source: Object, E: EventArgs){
          Message.InnerHtml = "Your name is: " + Name.Value
       }
    </script>
  
    <body>
          <form method=post runat=server>
  
            <h3> Enter Name: <input id="Name" type=text size=40 runat=server>
            </h3>
  
             <button OnServerClick=" FancyBtn_Click" runat=server>
               <b><I> I'm a fancy HTML 4.0 button </I> </b> 
             </button>
  
                       
           <h1>
             <span id="Message" runat=server></span>
           </h1>
  
          </form>
       </body>
 </html>
    

[Visual Basic, C#, JScript] The following example demonstrates how to programmatically specify and code an event handler for the ServerClick event.

[Visual Basic] 

<%@ Page Language="VB" AutoEventWireup="True" %>

<html> 

<head>

   <script runat="server">

      Sub Page_Load(sender As Object, e As EventArgs)

         ' Create a new HtmlButton control.
         Dim NewButtonControl As New HtmlButton()

         ' Set the properties of the new HtmlButton control.
         NewButtonControl.ID = "NewButtonControl"
         NewButtonControl.InnerHtml = "Click Me"

         ' Create an EventHandler delegate for the method you want to handle the event
         ' and then add it to the list of methods called when the event is raised.
         AddHandler NewButtonControl.ServerClick, AddressOf Button_Click 

         ' Add the new HtmlAnchor control to the Controls collection of the
         ' PlaceHolder control. 
         ControlContainer.Controls.Add(NewButtonControl)

      End Sub

      Sub Button_Click(sender As Object, e As EventArgs)

         ' Display a simple message. 
         Message.InnerHtml = "Thank you for clicking the button."

      End Sub

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlButton Constructor Example </h3>

      <asp:PlaceHolder ID="ControlContainer"
           runat="server"/>

      <br><br>
 
      <span ID="Message"
            runat="server"/>

   </form>

</body>
</html>

[C#] 

<%@ Page Language="C#" AutoEventWireup="True" %>

<html> 

<head>

   <script runat="server">

      void Page_Load(Object sender, EventArgs e)
      {

         // Create a new HtmlButton control.
         HtmlButton NewButtonControl = new HtmlButton();

         // Set the properties of the new HtmlButton control.
         NewButtonControl.ID = "NewButtonControl";
         NewButtonControl.InnerHtml = "Click Me";

         // Create an EventHandler delegate for the method you want to handle the event
         // and then add it to the list of methods called when the event is raised.
         NewButtonControl.ServerClick += new System.EventHandler(this.Button_Click); 

         // Add the new HtmlAnchor control to the Controls collection of the
         // PlaceHolder control. 
         ControlContainer.Controls.Add(NewButtonControl);

      }

      void Button_Click(Object sender, EventArgs e)
      {

         // Display a simple message. 
         Message.InnerHtml = "Thank you for clicking the button.";

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlButton Constructor Example </h3>

      <asp:PlaceHolder ID="ControlContainer"
           runat="server"/>

      <br><br>
 
      <span ID="Message"
            runat="server"/>

   </form>

</body>
</html>

[C++] No example is available for C++. To view a Visual Basic, C#, or JScript example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

HtmlButton Class | HtmlButton Members | System.Web.UI.HtmlControls Namespace | OnServerClick

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.