Web Server Controls->ASP.NET Label Control
Definition and Usage
The Label control is used to display text on a page. The text is programmable.
Note: This control lets you apply styles to its content!
Properties
| Property | Description |
|---|---|
| id | A unique id for the control |
| runat | Specifies that the control is a server control. Must be set to "server" |
| Text | The text to display in the label |
Examples
Label
ASPX Source:
| <script runat="server"> Sub submit(Sender As Object, e As EventArgs) label1.Text=txt1.Text End Sub </script> <html> <body> <form runat="server"> Write some text: <asp:TextBox id="txt1" Width="200" runat="server" /> <asp:Button id="b1" Text="Copy to Label" OnClick="submit" runat="server" /> <p><asp:Label id="label1" runat="server" /></p> </form> </body> </html> |
Output Result:
| Write some text: |
If you write some text "shaohai",in the textbox and then click the button "Copy to Label",it will show:
| Write some text:
shaohai |
In this example we declare one Label control, one TextBox control, and one Button control in an .aspx file. When the user clicks on the button, the submit subroutine is executed. The subroutine copies the content of the TextBox control to the Label control.
浙公网安备 33010602011771号