ASP.Net/Components/Register Form
Версия от 15:30, 26 мая 2010; (обсуждение)
Use Image as the indicator for validation (C#)
<%@ Page Language="C#" %>
<html>
<body>
<form runat=server>
<table cellspacing=10 cellpadding=2 border=0>
<tr>
<td>
<table cellspacing=0 cellpadding=1 border=0>
<tr valign=top>
<td/>
<td align=left><b><u>Account information:</u></b></td>
</tr>
<tr valign=top>
<td align=right><b>First name:</b></td>
<td><asp:TextBox ID="firstname" width=160 MaxLength=16 Text="" runat=server/></td>
<td><asp:RequiredFieldValidator id="FirstNameValidator"
ControlToValidate="firstname"
Display="Static"
ErrorMessage="First name must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator></td>
</tr>
<tr valign=top>
<td align=right><b>Last name:</b></td>
<td><asp:TextBox ID="lastname" width=160 MaxLength=16 Text="" runat=server/></td>
<td><asp:RequiredFieldValidator id="LastNameValidator"
ControlToValidate="lastname"
Display="Static"
ErrorMessage="Last name must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator></td>
</tr>
<tr valign=top>
<td align=right><b>E-mail address:</b></td>
<td><asp:TextBox ID="email" width=160 MaxLength=64 Text="" runat=server/>
<br/>(e.g. joe@foo.ru)
</td>
<td>
<asp:RequiredFieldValidator id="EmailValidator"
ControlToValidate="email"
Display="Dynamic"
ErrorMessage="E-mail address must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator id="EmailRegexValidator"
ControlToValidate="email"
Display="Dynamic"
ErrorMessage="E-mail must be of the form joe@develop.ru."
InitialValue="" width="100%" runat=server
ValidationExpression="[\w-]+@[\w-]+\.(com|net|org|edu|mil)$">
<img src="oops.gif"/>
</asp:RegularExpressionValidator>
</td>
</tr>
<tr valign=top>
<td align=right><b>Password:</b></td>
<td><asp:TextBox ID="password" TextMode="Password" width=160
MaxLength=10 Text="" runat=server/>
<br/>(4 to 10 characters)
</td>
<td><asp:RequiredFieldValidator id="PasswordValidator"
ControlToValidate="password"
Display="Dynamic"
ErrorMessage="Password must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator>
<asp:CompareValidator id="PasswordCompareValidator"
ControlToValidate="password"
ControlToCompare="confirm"
Display="None"
ErrorMessage="The two passwords you entered did not match, please reenter"
Type="String"
Operator="Equal"
runat=server />
</td>
</tr>
<tr valign=top>
<td align=right><b>Re-enter password:</b></td>
<td><asp:TextBox ID="confirm" width=160 MaxLength=10 Text=""
TextMode="Password" runat=server/>
</td>
<td><asp:RequiredFieldValidator id="ConfirmValidator"
ControlToValidate="confirm"
Display="Dynamic"
ErrorMessage="Re-enter password must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator></td>
</tr>
<tr valign=top>
<td/>
<td align=left><b><u>Shipping Address</u></b></td>
</tr>
<tr valign=top>
<td align=right><b>Company:</b></td>
<td><asp:TextBox ID="company" width=160 MaxLength=64 Text="" runat=server/>
</td>
</tr>
<tr valign=top>
<td align=right><b>Address Line 1:</b></td>
<td><asp:TextBox ID="address1" width=160 MaxLength=64 Text="" runat=server/>
</td>
<td><asp:RequiredFieldValidator id="Address1Validator"
ControlToValidate="address1"
Display="Static"
ErrorMessage="Address Line 1 must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator></td>
</tr>
<tr valign=top>
<td align=right><b>Address Line 2:</b></td>
<td><asp:TextBox ID="address2" width=160 MaxLength=64 Text="" runat=server/>
</td>
</tr>
<tr valign=top>
<td align=right><b>City:</b></td>
<td><asp:TextBox ID="city" width=160 MaxLength=64 Text="" runat=server/>
</td>
<td><asp:RequiredFieldValidator id="CityValidator"
ControlToValidate="city"
Display="Static"
ErrorMessage="City must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator></td>
</tr>
<tr valign=top>
<td align=right><b>State/Province:</b></td>
<td><asp:TextBox ID="stateprovince" width=160 MaxLength=64 Text="" runat=server/>
</td>
<td><asp:RequiredFieldValidator id="StateValidator"
ControlToValidate="stateprovince"
Display="Static"
ErrorMessage="State/Province must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator></td>
</tr>
<tr valign=top>
<td align=right><b>Zip/Postal Code:</b></td>
<td><asp:TextBox ID="zipcode" width=120 MaxLength=11 Text="" runat=server/>
</td>
<td>
<asp:RequiredFieldValidator id="ZipcodeValidator"
ControlToValidate="zipcode"
Display="Dynamic"
ErrorMessage="Zip/Postal Code must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator id="ZipcodeRegexValidator"
ControlToValidate="zipcode"
Display="Dynamic"
ErrorMessage="Zip/Postal Code must be 5 numerals."
InitialValue="" width="100%" ValidationExpression="\d{5}$" runat=server>
<img src="oops.gif"/>
</asp:RegularExpressionValidator>
</td>
</tr>
<tr valign=top>
<td align=right><b>Country:</b></td>
<td><asp:DropDownList id="country" runat=server>
<asp:ListItem select=True></asp:ListItem>
<asp:ListItem>United States</asp:ListItem>
<asp:ListItem>Albania</asp:ListItem>
<asp:ListItem>Algeria</asp:ListItem>
<asp:ListItem>Andorra</asp:ListItem>
<asp:ListItem>Angola</asp:ListItem>
<asp:ListItem>Anguilla</asp:ListItem>
<asp:ListItem>Antigua</asp:ListItem>
<asp:ListItem>Argentina</asp:ListItem>
<asp:ListItem>Armenia</asp:ListItem>
<asp:ListItem>Aruba</asp:ListItem>
<asp:ListItem>Australia</asp:ListItem>
<asp:ListItem>Austria</asp:ListItem>
<asp:ListItem>Azerbaijan</asp:ListItem>
<asp:ListItem>Azores</asp:ListItem>
<asp:ListItem>Bahamas</asp:ListItem>
<asp:ListItem>Bahrain</asp:ListItem>
<asp:ListItem>Bangladesh</asp:ListItem>
<asp:ListItem>Barbados</asp:ListItem>
<asp:ListItem>Belarus</asp:ListItem>
<asp:ListItem>Belgium</asp:ListItem>
<asp:ListItem>Belize</asp:ListItem>
<asp:ListItem>Benin</asp:ListItem>
<asp:ListItem>Bermuda</asp:ListItem>
<asp:ListItem>Bhutan</asp:ListItem>
<asp:ListItem>Bolivia</asp:ListItem>
<asp:ListItem>Bosnia-Herzegovina</asp:ListItem>
<asp:ListItem>Botswana</asp:ListItem>
<asp:ListItem>Brazil</asp:ListItem>
<asp:ListItem>British Virgin Islands</asp:ListItem>
<asp:ListItem>Brunei</asp:ListItem>
<asp:ListItem>Bulgaria</asp:ListItem>
<asp:ListItem>Burkina Faso</asp:ListItem>
<asp:ListItem>Burundi</asp:ListItem>
<asp:ListItem>Cambodia</asp:ListItem>
<asp:ListItem>Cameroon</asp:ListItem>
<asp:ListItem>Canada</asp:ListItem>
<asp:ListItem>Cape Verde</asp:ListItem>
<asp:ListItem>Cayman Islands</asp:ListItem>
<asp:ListItem>Central African Republic</asp:ListItem>
<asp:ListItem>Chad</asp:ListItem>
<asp:ListItem>Chile</asp:ListItem>
<asp:ListItem>China</asp:ListItem>
<asp:ListItem>Colombia</asp:ListItem>
<asp:ListItem>Comoros</asp:ListItem>
<asp:ListItem>Congo</asp:ListItem>
<asp:ListItem>Corsica</asp:ListItem>
<asp:ListItem>Costa Rica</asp:ListItem>
<asp:ListItem>Croatia</asp:ListItem>
<asp:ListItem>Cyprus</asp:ListItem>
<asp:ListItem>Czech Republic</asp:ListItem>
<asp:ListItem>Denmark</asp:ListItem>
<asp:ListItem>Djibouti</asp:ListItem>
<asp:ListItem>Dominica</asp:ListItem>
<asp:ListItem>Dominican Republic</asp:ListItem>
<asp:ListItem>Ecuador</asp:ListItem>
<asp:ListItem>Egypt</asp:ListItem>
<asp:ListItem>El Salvador</asp:ListItem>
<asp:ListItem>England</asp:ListItem>
<asp:ListItem>Equatorial Guinea</asp:ListItem>
<asp:ListItem>Eritrea</asp:ListItem>
<asp:ListItem>Estonia</asp:ListItem>
<asp:ListItem>Ethiopia</asp:ListItem>
<asp:ListItem>Faroe Islands</asp:ListItem>
<asp:ListItem>Fiji</asp:ListItem>
<asp:ListItem>Finland</asp:ListItem>
<asp:ListItem>France</asp:ListItem>
<asp:ListItem>French Guiana</asp:ListItem>
<asp:ListItem>French Polynesia</asp:ListItem>
<asp:ListItem>Gabon</asp:ListItem>
<asp:ListItem>Gambia</asp:ListItem>
<asp:ListItem>Georgia</asp:ListItem>
<asp:ListItem>Germany</asp:ListItem>
<asp:ListItem>Ghana</asp:ListItem>
<asp:ListItem>Gibraltar</asp:ListItem>
<asp:ListItem>Great Britain</asp:ListItem>
<asp:ListItem>Greece</asp:ListItem>
<asp:ListItem>Greenland</asp:ListItem>
<asp:ListItem>Grenada</asp:ListItem>
<asp:ListItem>Guadeloupe</asp:ListItem>
<asp:ListItem>Guatemala</asp:ListItem>
<asp:ListItem>Guinea</asp:ListItem>
<asp:ListItem>Guinea-Bissau</asp:ListItem>
<asp:ListItem>Guyana</asp:ListItem>
<asp:ListItem>Haiti</asp:ListItem>
<asp:ListItem>Honduras</asp:ListItem>
<asp:ListItem>Hong Kong</asp:ListItem>
<asp:ListItem>Hungary</asp:ListItem>
<asp:ListItem>Iceland</asp:ListItem>
<asp:ListItem>India</asp:ListItem>
<asp:ListItem>Indonesia</asp:ListItem>
<asp:ListItem>Ireland</asp:ListItem>
<asp:ListItem>Israel</asp:ListItem>
<asp:ListItem>Italy</asp:ListItem>
<asp:ListItem>Ivory Coast</asp:ListItem>
<asp:ListItem>Jamaica</asp:ListItem>
<asp:ListItem>Japan</asp:ListItem>
<asp:ListItem>Jordan</asp:ListItem>
<asp:ListItem>Kampuchea</asp:ListItem>
<asp:ListItem>Kazakhstan</asp:ListItem>
<asp:ListItem>Kenya</asp:ListItem>
<asp:ListItem>Kiribati</asp:ListItem>
<asp:ListItem>Korea</asp:ListItem>
<asp:ListItem>Kuwait</asp:ListItem>
<asp:ListItem>Kyrgyzstan</asp:ListItem>
<asp:ListItem>Laos</asp:ListItem>
<asp:ListItem>Latvia</asp:ListItem>
<asp:ListItem>Lebanon</asp:ListItem>
<asp:ListItem>Lesotho</asp:ListItem>
<asp:ListItem>Liberia</asp:ListItem>
<asp:ListItem>Liechtenstein</asp:ListItem>
<asp:ListItem>Lithuania</asp:ListItem>
<asp:ListItem>Luxembourg</asp:ListItem>
<asp:ListItem>Macao</asp:ListItem>
<asp:ListItem>Macedonia</asp:ListItem>
<asp:ListItem>Madagascar</asp:ListItem>
<asp:ListItem>Madeira Islands</asp:ListItem>
<asp:ListItem>Malawi</asp:ListItem>
<asp:ListItem>Malaysia</asp:ListItem>
<asp:ListItem>Maldives</asp:ListItem>
<asp:ListItem>Mali</asp:ListItem>
<asp:ListItem>Malta</asp:ListItem>
<asp:ListItem>Martinique</asp:ListItem>
<asp:ListItem>Mauritania</asp:ListItem>
<asp:ListItem>Mauritius</asp:ListItem>
<asp:ListItem>Mexico</asp:ListItem>
<asp:ListItem>Moldova</asp:ListItem>
<asp:ListItem>Mongolia</asp:ListItem>
<asp:ListItem>Montserrat</asp:ListItem>
<asp:ListItem>Morocco</asp:ListItem>
<asp:ListItem>Mozambique</asp:ListItem>
<asp:ListItem>Namibia</asp:ListItem>
<asp:ListItem>Nauru</asp:ListItem>
<asp:ListItem>Nepal</asp:ListItem>
<asp:ListItem>Netherlands</asp:ListItem>
<asp:ListItem>Netherlands Antilles</asp:ListItem>
<asp:ListItem>New Caledonia</asp:ListItem>
<asp:ListItem>New Zealand</asp:ListItem>
<asp:ListItem>Nicaragua</asp:ListItem>
<asp:ListItem>Niger</asp:ListItem>
<asp:ListItem>Nigeria</asp:ListItem>
<asp:ListItem>Northern Ireland</asp:ListItem>
<asp:ListItem>Norway</asp:ListItem>
<asp:ListItem>Oman</asp:ListItem>
<asp:ListItem>Pakistan</asp:ListItem>
<asp:ListItem>Panama</asp:ListItem>
<asp:ListItem>Papua New Guinea</asp:ListItem>
<asp:ListItem>Paraguay</asp:ListItem>
<asp:ListItem>Peru</asp:ListItem>
<asp:ListItem>Philippines</asp:ListItem>
<asp:ListItem>Poland</asp:ListItem>
<asp:ListItem>Portugal</asp:ListItem>
<asp:ListItem>Qatar</asp:ListItem>
<asp:ListItem>Reunion</asp:ListItem>
<asp:ListItem>Romania</asp:ListItem>
<asp:ListItem>Russia</asp:ListItem>
<asp:ListItem>Rwanda</asp:ListItem>
<asp:ListItem>Saint Kitts & Nevis</asp:ListItem>
<asp:ListItem>Saint Lucia</asp:ListItem>
<asp:ListItem>Saint Vincent</asp:ListItem>
<asp:ListItem>San Marino</asp:ListItem>
<asp:ListItem>Sao Tome and Principe</asp:ListItem>
<asp:ListItem>Saudi Arabia</asp:ListItem>
<asp:ListItem>Scotland</asp:ListItem>
<asp:ListItem>Senegal</asp:ListItem>
<asp:ListItem>Seychelles</asp:ListItem>
<asp:ListItem>Sierra Leone</asp:ListItem>
<asp:ListItem>Singapore</asp:ListItem>
<asp:ListItem>Slovakia</asp:ListItem>
<asp:ListItem>Slovenia</asp:ListItem>
<asp:ListItem>Solomon Islands</asp:ListItem>
<asp:ListItem>Somalia</asp:ListItem>
<asp:ListItem>South Africa</asp:ListItem>
<asp:ListItem>South Korea</asp:ListItem>
<asp:ListItem>Spain</asp:ListItem>
<asp:ListItem>Sri Lanka</asp:ListItem>
<asp:ListItem>Sudan</asp:ListItem>
<asp:ListItem>Suriname</asp:ListItem>
<asp:ListItem>Swaziland</asp:ListItem>
<asp:ListItem>Sweden</asp:ListItem>
<asp:ListItem>Switzerland</asp:ListItem>
<asp:ListItem>Syria</asp:ListItem>
<asp:ListItem>Taiwan</asp:ListItem>
<asp:ListItem>Tajikistan</asp:ListItem>
<asp:ListItem>Tanzania</asp:ListItem>
<asp:ListItem>Thailand</asp:ListItem>
<asp:ListItem>Togo</asp:ListItem>
<asp:ListItem>Tonga</asp:ListItem>
<asp:ListItem>Trinidad & Tobago</asp:ListItem>
<asp:ListItem>Tunisia</asp:ListItem>
<asp:ListItem>Turkey</asp:ListItem>
<asp:ListItem>Turkmenistan</asp:ListItem>
<asp:ListItem>Turks and Caicos Islands</asp:ListItem>
<asp:ListItem>Tuvalu</asp:ListItem>
<asp:ListItem>Uganda</asp:ListItem>
<asp:ListItem>Ukraine</asp:ListItem>
<asp:ListItem>United Arab Emirates</asp:ListItem>
<asp:ListItem>United States</asp:ListItem>
<asp:ListItem>Uruguay</asp:ListItem>
<asp:ListItem>Uzbekistan</asp:ListItem>
<asp:ListItem>Vanuatu</asp:ListItem>
<asp:ListItem>Vatican City</asp:ListItem>
<asp:ListItem>Venezuela</asp:ListItem>
<asp:ListItem>Vietnam</asp:ListItem>
<asp:ListItem>Wales</asp:ListItem>
<asp:ListItem>Wallis and Futuna Islands</asp:ListItem>
<asp:ListItem>Western Samoa</asp:ListItem>
<asp:ListItem>Yemen</asp:ListItem>
<asp:ListItem>Zaire</asp:ListItem>
<asp:ListItem>Zambia</asp:ListItem>
<asp:ListItem>Zimbabwe</asp:ListItem>
</asp:DropDownList></td>
<td><asp:RequiredFieldValidator id="CountryValidator"
ControlToValidate="country"
Display="Static"
ErrorMessage="Country must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator></td>
</tr>
<tr valign=top>
<td align=right><b>Day Phone:</b></td>
<td><asp:TextBox ID="dayphone" width=160 MaxLength=64 Text="" runat=server/>
</td>
<td>
<asp:RequiredFieldValidator id="DayphoneValidator"
ControlToValidate="dayphone"
Display="Dynamic"
ErrorMessage="Day Phone must be filled in."
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RequiredFieldValidator>
<asp:RegularExpressionValidator id="DayphoneRegexValidator"
ControlToValidate="dayphone"
Display="Dynamic"
ErrorMessage="The Day Phone must be formatted like (818) 555-1212."
ValidationExpression="(\s*[0-9]{5}$)|(^(\([1-9][0-9]{2}\)\s)?[1-9][0-9]{2}-[0-9]{4}(\sx\s*[0-9]{5})?$)"
InitialValue="" width="100%" runat=server>
<img src="oops.gif"/>
</asp:RegularExpressionValidator>
</td>
</tr>
<tr>
<td><br></td>
<td colspan=2><br>
<asp:Button Text="Submit" runat=server/>
</td>
</tr>
</table>
</td>
<td>
<asp:ValidationSummary id="valSum" runat=server
HeaderText="Please correct the following errors:"
ShowMessageBox="True"/>
</td>
</tr>
</table>
</form>
</body>
</html>