Home > Getting Started > ASP.NET Syntax > ASP.NET Syntax for HTML Controls > HtmlInputButton
ASP.NET Syntax ASP.NET Syntax for HTML Controls
Creates a push-button control.
Declarative Syntax
<input type = "button | submit | reset" id="accessID" runat="server"
onServerClick = "onServerClickHandler"
>
For information on the individual members of this class, see HtmlInputButton in the class library.
- This control does not require a closing tag.
The HtmlInputButton control enables programming of the HTML <input type=button
>, <input type=submit
>, and <input type=reset
> elements.
When a user clicks an HTMLInputButton control, input from the HtmlForm where the control is embedded is posted to the server, processed, and a response sent back to the requesting browser. This control is typically used in conjunction with other user input controls, such as the HtmlInputText, HtmlInputCheckBox, and HtmlSelect controls to gather user input that need to be processed on the server.
HtmlInputButton ( <input type=button
> ) functions similarly to HtmlButton ( <button
> ), except that it can target any HTML3.2-compliant browser.
The following samples illustrate use of the HtmlInputButton control.
This sample shows how to respond to an event triggered by a user clicking on an HtmlInputButton. When the button is clicked, program control is transferred to the button’s click event handler, which in this case simply specifies a message to display.
- In the BODY of the Web Forms document, declare the HtmlInputButton and the element where the message is to be rendered, in this case, a <
span runat="server" />
control.
<form runat="server">
<p><input type=button value="Do Something"
onServerClick = "Button1_Click" runat="server">
<p><span id="Message" runat="server" />
</form>
- In the <
head
> of the Web Forms page, define the button’s click event handler.
<script language="C#" runat="server">
void Button1_Click ( object Source, EventArgs e ) {
Message.InnerHtml = "Your message here";
}
</script>
The HtmlInputButton control also implements the functionality of HTML Submit and Reset button types. <input type=submit
> sends the form for processing, whereas <input type=reset
> restores all of the entry fields in a form to their initial values.
This sample illustrates use of Submit and Reset HtmlInputButtons to process a simple authentication scheme by comparing text entered by the user with text specified in event handling code.
- In the <
body
> of the Web Forms page, declare an HtmlForm control to contain two HtmlInputText controls, two HtmlInputButton controls, and a <span runat="server" />
control.
<form runat="server">
<p>Login: <input id="Name" runat="server">
<p>Password: <input type=password id="Password" runat="server">
<p><input type=submit value="Enter" runat="server"
onServerClick = "submitHandler">
<input type=reset runat="server" onServerClick = "resetHandler">
<p><span id="Message" runat="server" />
</form>
- In the <
head
> of the Web Forms page, define the event handlers for the submit and reset buttons.
<script language="C#" runat="server">
void submitHandler ( object Source, EventArgs e ) {
if ( Password.Value == "ASP.NET" ) Message.InnerHtml = "Password correct";
else Message.InnerHtml = "That password is not correct";
}
void resetHandler ( object Source, EventArgs e ) {
Name.Value = "";
Password.Value = "";
}
</script>
The submitHandler method in this case simply checks if the entry in the password field is "ASP.NET
", and the server sends back the appropriate response message. The resetHandler method simply clears both text boxes in the form.
Web Forms Events and Handlers HtmlInputButton Class