Export (0) Print
Expand All

HtmlButton Class

Allows programmatic access to the HTML <button> tag on the server.

For a list of all members of this type, see HtmlButton Members.

System.Object
   System.Web.UI.Control
      System.Web.UI.HtmlControls.HtmlControl
         System.Web.UI.HtmlControls.HtmlContainerControl
            System.Web.UI.HtmlControls.HtmlButton

[Visual Basic]
Public Class HtmlButton
   Inherits HtmlContainerControl
   Implements IPostBackEventHandler
[C#]
public class HtmlButton : HtmlContainerControl,
   IPostBackEventHandler
[C++]
public __gc class HtmlButton : public HtmlContainerControl,
   IPostBackEventHandler
[JScript]
public class HtmlButton extends HtmlContainerControl implements
   IPostBackEventHandler

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Remarks

The <button> element allows Web developers to create UI form buttons that can be composed of embedded HTML elements, including other server controls.

Note   The <button> element is defined in the HTML 4.0 specification and is supported only in Microsoft Internet Explorer version 4.0 and later. To create UI form buttons for use in other browsers, consider using the HtmlInputImage class.

To perform a set of custom instructions when the HtmlButton control is clicked, provide a custom event handler for the ServerClick event.

Note   The HtmlButton control renders JavaScript to the client browser. The client browser must have JavaScript enabled for this control to function properly. For more information on client script, see Client Script in Web Forms Pages.

For a list of initial property values for an instance of HtmlButton, see the HtmlButton constructor.

CAUTION   This control can be used to display user input, which might include malicious client script. Check any information that is sent from a client for executable script, SQL statements, or other code before displaying it in your application. ASP.NET provides an input request validation feature to block script and HTML in user input. Validation server controls are also provided to assess user input. For more information, see Validation Server Controls.

Example

[Visual Basic, JScript] The following example demonstrates how to use the ServerClick event to display the name entered in the text box.

[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>
    

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

Requirements

Namespace: System.Web.UI.HtmlControls

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

Assembly: System.Web (in System.Web.dll)

See Also

HtmlButton Members | System.Web.UI.HtmlControls Namespace | HtmlContainerControl | ServerClick | Client Script in Web Forms Pages

Show:
© 2014 Microsoft