Manipulate Text

The Label Web server control is used for displaying text on a Web page. You can work with the Label control in your code and programmatically change the properties of the label, including the text that appears.

You can use the Label Web control to identify the purpose of controls that you arrange on a Web form. For example, you can have 3 TextBox controls on a form. You need to identify what each TextBox contains.

The Label Web control will reside on a server form on your ASP.NET page. The Label control is created with the <ASP: Label> tag. You will need an id attribute to give the control a name, which is how you reference it in code. As with other Web server controls, set the runat attribute to Server. Like the Image Web server control, the Label Web server control does not support any events.

For example, you can have a form that takes input using a TextBox control. After filling in the text box, users can click a button, which fires off an event that can read what was in the text box and update a Label control on the form with this value.

^ Untitled - Notepad

D Open the

WebWelcomeTemplate.aspx template from the Code Templates directory.

< Add a button to the pages that calls the

Button_OnClick event.

0 Save the file and request it from the Web server.

3e a message in the box.

0 Ty text

_Q Click the Submit button.

I A message appears.

D Open the

WebWelcomeTemplate.aspx template from the Code Templates directory.

^0 Add a Text box to the page.

■ Note the Label control on the page.

< Add a button to the pages that calls the

Button_OnClick event.

—□ Modify the code in the Button_OnClick event so that the label is updated with the text from the text box.

0 Save the file and request it from the Web server.

Note: See pages 20 to 25 for instructions on saving a file to the Web server and then requesting the file using the IIS Admin.

3e a message in the box.

0 Ty text

_Q Click the Submit button.

I A message appears.

WORK WITH WEB CONTROLS

WORK WITH WEB CONTROLS

Was this article helpful?

0 0

Post a comment