In previous tips, I've talked about the benefits of generating your HTML code using ASP code, like this:
Response.Write "<html><head>"
Under Windows NT 4.0 (IIS 4.0), this method runs faster than creating a mix of HTML and ASP blocks within the same page.
Along the same lines, there's no reason you can't create utility functions to build some of the HTML for you. For instance, when I'm building input forms, I often need to create text boxes. Instead of duplicating all the Response.Write statements, I've created a series of functions to generate each type of control for me. (Incidentally, this is similar to how ASP+ works.) Here's my HTMLTextBox function:
Sub HTMLTextBox(blnInTable, strName, strSize, strMaxLength, strValue)
If blnInTable = CTRL_IN_TABLE Then WriteLine "<td>"
WriteLine "<input type=""text"" name=" & DQ & strName & DQ _
& " size=" & DQ & strSize & DQ _
& " maxlength=" & DQ & strMaxLength & DQ _
& " value=" & DQ & strValue & DQ & ">"
If blnInTable = CTRL_IN_TABLE Then WriteLine "</td>"
End Sub
I have a couple of constants defined to indicate whether to put the text box into a table cell (which I often do):
Const CTRL_IN_TABLE = True
Const CTRL_NO_TABLE = False
In addition, I use the WriteLine routine covered in previous tips:
Sub WriteLine(strText)
Response.Write strText & vbCrLf
End Sub
This type of code lets me focus on the function of the page, not how I render it. If you are using JavaScript to verify that fields are filled in, there's no reason you can't expand the function to force the field to be required. In that case, having a routine build the code keeps the code consistent across the application.