Web Pages Tutor...login
Web Pages Tutorial
author:php.cn  update time:2022-04-11 14:20:28

Web Forms Button


ASP.NET Web Forms - Button control


The Button control is used to display a push button.


Button control

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

The submit button has no command name, and when it is clicked, it passes the page back to the server. You can write some event handlers to control the execution of actions when the submit button is clicked.

Command buttons have command names and allow you to create multiple Button controls on the page. You can write some time handles to control the execution of actions when the command button is clicked.

The properties and properties of the Button control are listed in our WebForms Controls Reference Manual 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>


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 the submit button is triggered, the submit subroutine will be executed. The submit subroutine will write a line of text into the Label control:

Example

<script  runat="server">
Sub submit(sender As Object, e As EventArgs)
   lbl1.Text="Your name is " & txt1.Text
End Sub
</script>

<!DOCTYPE html>
<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>

Run Example»

Click "Run instance" button to view the online instance


php.cn