Wednesday 16 July 2008

CSS

Use of CSS to control all layout of web pages is strongly encouraged. Resist using HTML to control any presentation at all. Tables should only be used for tabular data.
To associate a CSS page with a HTML page a LINK should be placed within the header section.
Within Visual Studio, import or add a CSS page to a project, and then drag it into the header.

Example of CSS element:
p
{
font-weight: normal;
font-size: medium;
color: black;
font-family: Verdana;
}

Example of CSS (user defined) Class:

.headerlabel
{
font-weight: bold;
font-size: large;
vertical-align: middle;
color: red;
background-color: black;
text-align: center;
}

Thursday 10 July 2008

ASP.Net Controls

Textbox control
Many of the properties of the text box are self-explanatory.
Here are some of the less intuitive ones.

AccessKey: Allows user to enter the textbox by pressing a defined key combination. This is not considered good design practice.
AutoPostBack: if true, if the user edits the contents, when they leave the control the contents of the textbox are automatically sent back to the server. This is not a recommended property to use.
It is possible to pick up the TextChanged event and respond to the user input.
AutoCompleteType: If the browser supports AutoComplete, this determins which element is used to populate this text box. There is a list of permitted values here. For example, Email, LastName, BusinessPhone. In the properties box their is a drop down list of valid entries next to this property. I tested this, by setting this value to "Email" firefox flagged it as autocompletable and when I clicked Autofill it entered my email address. I should use this feature whereever applicable.
Focus: Set this property in the form load event to determin which control receives the focus once the page has loaded. Useful.

VALIDATION CONTROLS
There are several useful controls for validating user input. A particularly good one is the Regular Expressions Validation control. For example, here is a regex to check that input is a valid email address: ^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([0-9]{1,3})|([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$
This one checks UK postcodes: ^[A-Za-z]{1,2}[\d]{1,2}([A-Za-z])?\s?[\d][A-Za-z]{2}$

This was copied from this site which has a number of Regex statements for a variety of purposes. http://regexlib.com/DisplayPatterns.aspx
Another validation control is the requiredfieldvalidator.
This functionality (in ASP.net 3.5) works in IE, Firefox and Opera.
For non-supported browsers check the Page.IsValid property. This will be false if any of the validation checks failed.
There is a range validator to check that values are in a certain range.
With each of the validation controls there is a Text property and an Error property.
The text is what will show in the error validator, the error message is what will display in the error summary if one is included in the page. So the text could be set to something like "Required" and the error message could be "please enter a valid email address".
The error summary has a number of properties, for example it will display errors in a message box in up-level browsers.

I have reached page 172 in the book, which contains an important section on Ajax validation. This is a key goal of what I am trying to achieve.