Latest web development tutorials

ASP.NET Button control

Button control is used to display a push button.


Button controls

Button control is used to display a push button. Push button may be a submit button or a command button. By default, this control is a submit button.

Submit button does not have a command name when it is clicked, it will transfer the page back to the server. You can write some event handlers, when the submit button is clicked, used to control the implementation of the action.

Command button has a command name, and allows you to create multiple Button controls on a page. You can write some time to handle, when the command button is clicked, it used to control the implementation of the action.

Button control properties and attributes listed in our WebForms Controls reference page .

The following example demonstrates a simple Button control:

<html>
<body>

<form runat="server">
<asp:Button id="b1" Text="Submit" runat="server" />
</form>

</body>
</html>


Adding a script

Forms often submitted by clicking the button.

In the following example, we declare a TextBox control in an .aspx file, a Button control and a Label control. When the submit button is triggered, submit subroutine will be executed. submit subroutine writes a line of text to the Label control:

Examples

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

The demonstration >>