다음을 통해 공유


HtmlInputButton Control

Creates a server-side control that maps to the <input type=button>, <input type=submit>, and <input type=reset> HTML elements and allows you to create a command button, submit button, or reset button, respectively.

<input type=button | submit | reset
       id="programmaticID"
       OnServerClick="onserverclickhandler"
       runat="server" >

Remarks

Use the HtmlInputButton control to program against the <input type=button>, <input type=submit>, and <input type=reset> HTML elements. When a user clicks an HtmlInputButton control, input from the form that the control is embedded on is posted to the server and processed. A response is then sent back to the requesting browser.

By providing a custom event handler for the ServerClick event, you can perform a specific set of instructions when the control is clicked.

Note   A reset button does not support the ServerClick event. When a reset button is clicked, all input controls on the page are not necessarily cleared. Instead, they are returned to their original state when the page was loaded. For example, if a text box originally contained the value "JohnDoe", clicking on the reset button would return the text box to this value.

When used in conjunction with the HtmlInputText and HtmlTextArea controls, you can create user input or authentication pages that can be processed on the server.

Note   This control does not require a closing tag.

Example

The following example demonstrates how to use an HtmlInputButton control to submit a form to the server for processing.

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

<html> 

<head>

   <script runat="server">

      Protected Sub AddButton_Click(sender As Object, e As EventArgs)

         Dim Answer As Integer

         Answer = Convert.ToInt32(Value1.Value) +
                  Convert.ToInt32(Value2.Value)

         AnswerMessage.InnerHtml = Answer.ToString()

      End Sub

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlInputButton Example </h3>




















































      <table>
         <tr>
            <td colspan="5">
               Enter integer values into the text boxes. <br>
               Click the Add button to add the two values. <br>
               Click the Reset button to reset the text boxes.
            </td>
         </tr>
         <tr>
            <td colspan="5">
               &nbsp;
            </td>
         </tr>
         <tr align="center">
            <td>
               <input ID="Value1"
                      Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                      runat="server"/>
            </td>
            <td>
               + 
            </td>
            <td>
               <input ID="Value2"
                      Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                      runat="server"/>
            </td>
            <td>
               =
            </td>
            <td>
               
               <span ID="AnswerMessage"
                     runat="server"/>
            </td>
         </tr>
         <tr>
            <td colspan="2">
               <asp:RequiredFieldValidator
                    ID="Value1RequiredValidator"
                    ControlToValidate="Value1"
                    ErrorMessage="Please enter an value.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="Value1MinCompareValidator"
                    ControlToValidate="Value1"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="Value1MaxCompareValidator"
                    ControlToValidate="Value1"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>
            </td>
            <td colspan="2">
               <asp:RequiredFieldValidator
                    ID="Value2RequiredValidator"
                    ControlToValidate="Value2"
                    ErrorMessage="Please enter an value.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="Value2MinCompareValidator"
                    ControlToValidate="Value2"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="Value2MaxCompareValidator"
                    ControlToValidate="Value2"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>
            </td>
            <td>
               &nbsp
 
            </td
         </tr>
         <tr align="center">
            <td colspan="4">
               <input Type="Submit"
                      Name="AddButton
                      Value="Add"
                      OnServerClick="AddButton_Click"
                      runat="server"/>
               &nbsp;&nbsp;&nbsp;
               <input Type="Reset"
                      Name="AddButton
                      Value="Reset"
                      runat="server"/>
            </td>
            <td>
               &nbsp;
            </td>
         </tr>
      </table>


   </form>

</body>
</html>
[C#]
<%@ Page Language="C#" AutoEventWireup="True" %>

<html> 

<head>

   <script runat="server">

      protected void AddButton_Click(Object sender, EventArgs e)
      {
         int Answer;

         Answer = Convert.ToInt32(Value1.Value) +
                  Convert.ToInt32(Value2.Value);

         AnswerMessage.InnerHtml = Answer.ToString();

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlInputButton Example </h3>




















































      <table>
         <tr>
            <td colspan="5">
               Enter integer values into the text boxes. <br>
               Click the Add button to add the two values. <br>
               Click the Reset button to reset the text boxes.
            </td>
         </tr>
         <tr>
            <td colspan="5">
               &nbsp;
            </td>
         </tr>
         <tr align="center">
            <td>
               <input ID="Value1"
                      Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                      runat="server"/>
            </td>
            <td>
               + 
            </td>
            <td>
               <input ID="Value2"
                      Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                      runat="server"/>
            </td>
            <td>
               =
            </td>
            <td>
               
               <span ID="AnswerMessage"
                     runat="server"/>
            </td>
         </tr>
         <tr>
            <td colspan="2">
               <asp:RequiredFieldValidator
                    ID="Value1RequiredValidator"
                    ControlToValidate="Value1"
                    ErrorMessage="Please enter an value.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="Value1MinCompareValidator"
                    ControlToValidate="Value1"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="Value1MaxCompareValidator"
                    ControlToValidate="Value1"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>
            </td>
            <td colspan="2">
               <asp:RequiredFieldValidator
                    ID="Value2RequiredValidator"
                    ControlToValidate="Value2"
                    ErrorMessage="Please enter an value.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="Value2MinCompareValidator"
                    ControlToValidate="Value2"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="Value2MaxCompareValidator"
                    ControlToValidate="Value2"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>
            </td>
            <td>
               &nbsp
 
            </td
         </tr>
         <tr align="center">
            <td colspan="4">
               <input Type="Submit"
                      Name="AddButton
                      Value="Add"
                      OnServerClick="AddButton_Click"
                      runat="server"/>
               &nbsp;&nbsp;&nbsp;
               <input Type="Reset"
                      Name="AddButton
                      Value="Reset"
                      runat="server"/>
            </td>
            <td>
               &nbsp;
            </td>
         </tr>
      </table>


   </form>

</body>
</html>

See Also

ASP.NET Syntax for HTML Controls | Class