ASP.NET Server Components       
by Douglas Reilly	


Example 1: 

<td>
    <asp:TextBox runat="server" TextMode="Password" 
Width="100" 
ID="NewPassword2"></asp:TextBox>
</td>
<td>
    <asp:RequiredFieldValidator 
ErrorMessage="*" 
runat="server" 
display="Dynamic" 
ControlToValidate="NewPassword2" 
id="RequiredFieldValidator3">
</asp:RequiredFieldValidator>
    <asp:CompareValidator ControlToValidate="NewPassword2" 
runat="server" Display="Dynamic" 
ControlToCompare="NewPassword" 
ErrorMessage="Please enter and re-enter 
the same new password" 
id="CompareValidator1">
</asp:CompareValidator>
</td>


Example 2:

public class ReformatSSN : System.Web.UI.WebControls.BaseValidator,
                           IPostBackDataHandler,IPostBackEventHandler


Example 3:

protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
    if ( Page.IsPostBack )
    {
        ServerFormatSSN();
        IsValid=bIsValid;
    }
    if ( Page.ClientTarget.ToLower()!="downlevel" )
    {
    Page.RegisterClientScriptBlock(
     "FormatSSNClientScript", "<" + 
     "SCRIPT Language=JavaScript SRC=\"FormatSSN.js\"></" + "SCRIPT>");
    }
}


Listing One
<%@ Page Language="vb" AutoEventWireup="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>WebForm1</title>
        <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
        <meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
        <meta content="JavaScript" name="vs_defaultClientScript">
        <meta 
content=http://schemas.microsoft.com/intellisense/ie5 name="vs_targetSchema">
    </HEAD>
    <body>
    <form id="Form1" method="post" runat="server">
        <table width="500">
            <tr>
                <td align="right" width="33%">Old Password:
                </td>
                <td><asp:textbox id="OldPassword" 
runat="server" 
Width="100" 
TextMode="Password">
</asp:textbox></td>
                <td>
<asp:requiredfieldvalidator 
id="RequiredFieldValidator1" 
runat="server" 
display="Dynamic" ControlToValidate="OldPassword" ErrorMessage="*">
</asp:requiredfieldvalidator></td>
            </tr>
            <tr>
                <td align="right" width="33%">New Password:
                </td>
                <td>
<asp:textbox id="NewPassword" 
runat="server" Width="100" TextMode="Password">
</asp:textbox></td>
                <td>
<asp:requiredfieldvalidator 
id="RequiredFieldValidator2" 
runat="server" display="Dynamic" 
ControlToValidate="NewPassword" 
ErrorMessage="*">
</asp:requiredfieldvalidator>
</td>
            </tr>
            <tr>
                <td align="right" width="33%">Re-Enter:
                </td>
                <td>
<asp:textbox id="NewPassword2" 
    runat="server" Width="100" 
TextMode="Password">
</asp:textbox>
</td>
                <td>
<asp:requiredfieldvalidator 
id="RequiredFieldValidator3" 
runat="server" display="Dynamic" 
ControlToValidate="NewPassword2" 
ErrorMessage="*">
</asp:requiredfieldvalidator>
<asp:comparevalidator
id="CompareValidator1" 
runat="server" 
ControlToValidate="NewPassword2" 
ErrorMessage=
"Please enter and re-enter the same new password" 
ControlToCompare="NewPassword" 
Display="Dynamic">
</asp:comparevalidator>
</td>
            </tr>
            <tr>
                <td align="middle" colSpan="3">
<asp:button id="Button1" Runat="server" 
Text="Submit">
</asp:button>
</td>
            </tr>
        </table>
        </form>
    </body>
</HTML>


Listing Two
<%@ Register TagPrefix="DDJ" Namespace="DDJ" 
Assembly="FormatDateControl" %>
<%@ Page Language="vb" AutoEventWireup="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
    <HEAD>
        <title>WebForm2</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
        <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
        <meta name="vs_defaultClientScript" content="JavaScript">
        <meta name="vs_targetSchema" 
                   content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body>
        <form id="Form1" method="post" runat="server">
            &nbsp;
            <table width="500">
                <tr>
                    <td width="50%" align="right">
                        SSN:
                    </td>
                    <td>
                        <DDJ:ReformatSSN 
id="ReformatSSN1" 
runat="server">
</DDJ:ReformatSSN><br>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" align="center">
                        <asp:Button id="Button1" 
runat="server" 
Text="Button">
</asp:Button>
                    </td>
                </tr>
            </table>
        </form>
    </body>
</HTML>






4

