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:



Home » ASP » Article

ASP.NET : Control Attributes

Article by: David Sussman, et al (7/8/2002)
Bookmark us now! Add to Favourites
Email a friend!Tell a friend
Summary: How do we get hold of the <asp:label> control attributes within our ASP.NET code? Well, we can do this by adding some ASP.NET code at the head of the HTML, as in the following example
Viewed: 63311 times Rating (12 votes): 
 3.5 out of 5
 Rate this Article  Read Comments  Post Comments


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

Control Attributes

This still leaves one question unanswered though. How do we get hold of the <asp:label> control attributes within our ASP.NET code? Well, we can do this by adding some ASP.NET code at the head of the HTML, as in the following example. First delete the Text attribute at the end of both <asp:label> controls:

 

...

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

you have selected to receive information about

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

...

 

Now add the following ASP.NET script block before your HTML code:

 

<script language="C#" runat="server">

void Page_Load()

{

Message1.Text = "Vervain";

Message2.Text = "Madrid";

}

</script>

 

<html>

<head>

<title>Label Control page</title>

...

 

You must make sure that you type this part in exactly, using exactly the same case in the letters, otherwise it won't work. So if you typed Void page_load() for example instead of void Page_Load() then you would get an error. The same holds true for all of the examples in this chapter and indeed the book. If any example doesn't work when you first try it, check the cases are correct. This is because C# is a case-sensitive language. It can be awkward to get use to at first but once you get used to it, it will be like second nature.

 

So, if you run the example now, you'll see that the output has changed:

 


Ignore the void Page_Load() statement and it's accompanying curly braces (we'll discuss this in Chapter 7): it's the code contained within the curly braces that's important for now:

 

Message1.Text = "Vervain";

 

In the first line Message1 refers to the identity of our first <asp:label> control, while the Text attribute refers to the actual text that we wish to set. So we're saying "set the Method1 <asp:label>'s Text attribute to Vervain". The second line:

 

Message2.Text = "Madrid";

 

does just the same for the Message2 <asp:label> control, setting the text attribute to Madrid.

This is reflected in the final display of our web form. This ASP.NET code has allowed us to directly influence the contents of the <asp:label> control, and set it separately, independently from our HTML code. You should also note that both lines are ended by a semi-colon. In C#, every line should be completed by a semi-colon.

 

So all of the HTML server controls are created as separate objects, which you can access with ASP.NET code. These objects allow you to reference any of the attributes of the server control as follows:

 

[ServerControl].[ServerControlAttribute]

 

So you could make the control invisible by setting the Visible attribute to false:

 

Message.Visible = "false";

 

Let's now move on to a more complex control.

Previous Page  Page 1 Page 2 Page 3 Page 4 Page 5  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.






CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums
Rate this article:     Poor Excellent
View highlighted Comments
User Comments on 'ASP.NET : Control Attributes'
RELATED ARTICLES
ASP FilesystemObject
by Jeff Anderson
An introduction to the Filesystemobject
ASP GetTempName
by Jeff Anderson
Use the GetTempName method to create a randomly generated temporary file on the server.
ASP Format Date and Time Script
by Jeff Anderson
An ASP script showing the variety of date and time formats possible using the FormatDateTime Function.
ASP OpenTextFile
by Jeff Anderson
An introduction to the OpenTextFile Method of the FileSystemObject
Email validation using Regular Expression
by Jeff Anderson
Using regular expression syntax is an exellent way to thoroughly validate an email. It's possible in ASP.
Add or Subtract Hours in SQL or ASP using DateAdd
by Jeff Anderson
A beginners guide to using the SQL DATEADD function to add or subtract hours. Particularly useful when setting the time displayed on the ASP page to a different time zone (eg when the server is in the US, and the site is for a UK audience).
The asp:radiobutton and asp:radiobuttonlist control
by David Sussman, et al
In HTML, radio buttons are used when we need to make multiple sets of choices available, but we want the user to select only one of them.
The asp:checkbox and asp:checkboxlist control
by David Sussman, et al
Checkboxes are similar to radio buttons, and in HTML, they were used to allow multiple choices from a group of buttons.
ASP FileExists
by Jeff Anderson
An introduction to the FileExistsMethod of the FileSystemObject
Concatenate strings in sql
by Jeff Anderson
A brief introduction to concatenating strings in an sql query (using SQL server or access databases).








Recent Forum Threads
• Global.Mapper.v15.2.3.b060614
• Geometric_Glovius_Pro_v3.6.1
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2
• Petrel.V2013.2
• Altair.HyperWorks.v12
• VoluMill.v6.1
• VoluMill.NEXION.6
• VERO.SurfCAM.v2014


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