codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:



Previous Page  Page 1 Page 2 Page 3 Page 4  Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 Page 13 Next Page  

<asp:label> Control Examples

To create the control with the minimum of information needed, you can just supply the runat and
id attributes:

 

<asp:label id="Message1" runat="server">Hello</asp:label>

 

Placed in the context of a web page, the control might look like this:

 

<html>

<head>

<title>Another Hello World Page </title>

</head>

<body>

Hello

<asp:label id="Message1" runat="server"> World</asp:label>

</body>

</html>

 

The id attribute is used to uniquely identify the <asp:label> control so you can refer to it in your ASP.NET code. The runat="server" attribute tells the server to process the control and generate HTML code to be sent to the client.


Let's look at another example. If you want to set the color of a text message to red, you could set it like this:

 

<asp:label id="Message1" forecolor="red" runat="server">Hello</asp:label>

 

Alternatively, you can use the text attribute. This way, everything can be contained within the opening tag, in which case you need to close the tag in the following way:

 

<asp:label id="Message1" forecolor="red" text="Hello" runat="server" />

 

Here, we omit the closing tag, and just supply a closing / to indicate that the tag is closed. Throughout the book, if the tag doesn't enclose any content, then we will use this latter notation in preference to having a closing tag.

 

The <asp:> prefix indicates that this control is part of the set of built-in ASP.NET controls. It is possible to create custom controls, which have prefixes of the developer's choice. We will look at this later in the book.

 

Let's now take a look at an example of how we can use the <asp:label> control to display some text at requisite places within our web page. In this example, we'll assume that values of the user's name and the destination they selected on our holiday web site have already been passed across, and that all we need to do is output a message displaying confirmation that we have received the user's details.

Try It Out Using the <asp: label> Control

1.       Enter the following code in your web page editor:

 

<html>

<head>

<title>Label Control page</title>

</head>

<body>

<h1>Feiertag Holidays</h1>

<br /><br />

Thank you

<asp:label id="Message1" runat="server" text="Chris"/>

you have selected to receive information about

<asp:label id="Message2" runat="server" text="Oslo"/>

. The information pack will be sent out within the next 24 hours.

</body>

</html>


 

2.       Save this as labelcontrol.aspx, in your test directory, and view it from your browser:

 

 

How It Works

There isn't much to explain here. Our <asp:label> controls fit neatly within the HTML code:

 

<h1>Feiertag Holidays</h1>

<br /><br />

Thank you

<asp:label id="Message1" runat="server" text="Chris"/>

you have selected to receive information about

<asp:label id="Message2" runat="server" text="Oslo"/>

.The information pack will be sent out within the next 24 hours.

</body>

 

For all intents and purposes the <asp:label> control could be an HTML control. The only thing that differentiates it is the fact that it is executed on the server. The only way you can note this is by checking the underlying HTML source code that is sent back to the browser:

 

<h1>Feiertag Holidays</h1>

<br /><br />

Thank you

<span id="Message1">Chris</span>

you have selected to receive information about

<span id="Message2">Oslo</span>

.The information pack will be sent out within the next 24 hours.

</body>

 

The <asp:label> controls are translated into HTML <span> tags, to which they are functionally equivalent.

Previous Page  Page 1 Page 2 Page 3 Page 4  Page 6 Page 7 Page 8 Page 9 Page 10 Page 11 Page 12 Page 13 Next Page  




Click here to Buy!

Buy Beginning ASP.NET with C# here

© Copyright 2002 Wrox Press This chapter is written by David Sussman, et al and taken from "Beginning ASP.NET with C#" published by Wrox Press Limited in June 2002; ISBN 1861007345; copyright Wrox Press Limited 2002; all rights reserved.

No part of these chapters may be reproduced, stored in a retrieval system or transmitted in any form or by any means -- electronic, electrostatic, mechanical, photocopying, recording or otherwise -- without the prior written permission of the publisher, except in the case of brief quotations embodied in critical articles or reviews.











Recent Forum Threads
• Run a program both on windows and linux
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2
• Petrel.V2013.2
• Altair.HyperWorks.v12
• VoluMill.v6.1
• VoluMill.NEXION.6
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2


Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text


© Copyright codetoad.com 2001-2014