ASP.NET - Button control
- Previous Page WebForms TextBox
- Next Page WebForms Data Binding
The Button control is used to display a button.
Button control
The Button control is used to display buttons. Buttons can be submit buttons or command buttons, and the control belongs to the submit button.
The 'submit' button does not have a command name, and when it is clicked, it sends the page back to the server. Some event handlers can be written to control the execution of actions when the submit button is clicked.
command buttons have named names and allow you to create multiple Button controls on the page. You can write some event handlers to control the execution of actions when the command button is clicked.
The properties of the Button control are listed in our Button Control Reference Manual.
The following example demonstrates a simple Button control:
<html> <body> <form runat="server"> <asp:Button id="b1" Text="Submit" runat="server" /> </form> </body> </html>
Add Script
Forms are usually submitted by clicking a button.
In the following example, we declare a TextBox control, a Button control, and a Label control in the .aspx file. When this submit button is clicked, the submit subroutine will be executed. The submit subroutine will write a text to the Label control:
<script runat="server"> Sub submit(sender As Object, e As EventArgs) lbl1.Text="Your name is " & txt1.Text End Sub </script> <html> <body> <form runat="server"> Enter your name: <asp:TextBox id="txt1" runat="server" /> <asp:Button OnClick="submit" Text="Submit" runat="server" /> <p><asp:Label id="lbl1" runat="server" /></p> </form> </body> </html>
- Previous Page WebForms TextBox
- Next Page WebForms Data Binding