loads of useful information, examples and tutorials pertaining to web development utilizing asp.net, c#, vb, css, xhtml, javascript, sql, xml, ajax and everything else...

 




Automatic Required Field Validators


First Name:
<asp:TextBox ID="txtFirst_Name_req" runat="server" />
This will get a validator as it's id is trailed by '_req'
Last Name:
<asp:TextBox ID="txtLastName_req" runat="server />
This will get a validator, but it will not be nicely formatted as LastName is not seperated by a '_'
Middle Initial:
<asp:TextBox ID="txtMiddle_Initial" runat="server" MaxLength="1" Width="20" />
This will not get a validator as there is no trailing '_req'
Favorite Sport:
<asp:DropDownList ID="dropSport_req" runat="server">...</asp:DropDownList>
This will get a validator, but since the prefix 'drop' was not specified to be trimmed, it will show up in the validator
Referred by:
<asp:DropDownList ID="ddlReferred_By_req" runat="server">...</asp:DropDownList>
This will get a properly formatted validator, but it will never run because the 'empty' string specified in the function was "-select-" and this control has a default of "-choose-" so the validator will not see it as empty



Code & Explanation