Condividi tramite


Procedura: personalizzare il controllo CreateUserWizard ASP.NET

Aggiornamento: novembre 2007

È possibile personalizzare il contenuto del controllo CreateUserWizard utilizzando i modelli CreateUserWizardStep e CompleteWizardStep. Grazie alla specifica del contenuto dei modelli, è possibile indicare l'interfaccia utente personalizzata che include controlli utilizzati dal controllo CreateUserWizard per raccogliere informazioni sul nuovo utente, nonché ulteriori controlli specificati (per un elenco dei controlli utilizzati dal controllo CreateUserWizard, vedere Personalizzazione dell'aspetto dei controlli di accesso ASP.NET.)

Inoltre, poiché il controllo CreateUserWizard eredita dalla classe Wizard, è possibile aggiungere passaggi personalizzati al controllo CreateUserWizard. Per ulteriori informazioni sul controllo Wizard, vedere Cenni preliminari sul controllo server Web Wizard.

Nota:

È anche possibile personalizzare l'aspetto del controllo CreateUserWizard utilizzando i temi e le proprietà degli stili. Per informazioni dettagliate, vedere Cenni preliminari su temi e interfacce ASP.NET e le proprietà del controllo CreateUserWizard.

Per personalizzare i passaggi CreateUserWizard

  1. Inserire un controllo CreateUserWizard nella pagina utilizzando la sintassi seguente:

    <asp:CreateUserWizard ID="CreateUserWizard1" Runat="server">
      <WizardSteps>
        <asp:CreateUserWizardStep >
        </asp:CreateUserWizardStep>
        <asp:CompleteWizardStep >
        </asp:CompleteWizardStep>
      </WizardSteps>
    </asp:CreateUserWizard>
    
  2. Per personalizzare il passaggio di creazione dell'account, creare un elemento <ContentTemplate> all'interno dell'elemento <asp:CreateUserWizardStep>. Nel modello aggiungere il markup e i controlli per definire il layout e il contenuto dell'interfaccia utente per la raccolta delle informazioni sull'utente necessarie.

    Nota:

    Se il provider di appartenenze estende la classe MembershipProvider con membri personalizzati, è necessario aggiungere qualsiasi controllo per raccogliere le informazioni personalizzate richieste dal provider per la creazione di un nuovo utente. Per informazioni dettagliate, vedere CreateUserWizardStep.

    Nell'esempio di codice riportato di seguito viene illustrata una proprietà CreateUserStep che include controlli CheckBox che consentono agli utenti di specificare ulteriori opzioni.

    <asp:CreateUserWizardStep ID="CreateUserWizardStep1" >
        <ContentTemplate>
            <table border="0" style="font-size: 100%; font-family: Verdana">
                <tr>
                    <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                        Sign Up for Your New Account</td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="UserNameLabel"  AssociatedControlID="UserName">
                            User Name:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="UserName" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="UserNameRequired"  ControlToValidate="UserName"
                            ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="PasswordLabel"  AssociatedControlID="Password">
                            Password:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="Password"  TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="PasswordRequired"  ControlToValidate="Password"
                            ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="ConfirmPasswordLabel"  AssociatedControlID="ConfirmPassword">
                            Confirm Password:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="ConfirmPassword"  TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ConfirmPasswordRequired"  ControlToValidate="ConfirmPassword"
                            ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
                            ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="EmailLabel"  AssociatedControlID="Email">
                            E-mail:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="Email" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="EmailRequired"  ControlToValidate="Email"
                            ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="QuestionLabel"  AssociatedControlID="Question">
                            Security Question:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="Question" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="QuestionRequired"  ControlToValidate="Question"
                            ErrorMessage="Security question is required." ToolTip="Security question is required."
                            ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="AnswerLabel"  AssociatedControlID="Answer">
                            Security Answer:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="Answer" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="AnswerRequired"  ControlToValidate="Answer"
                            ErrorMessage="Security answer is required." ToolTip="Security answer is required."
                            ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="2">
                        <asp:CompareValidator ID="PasswordCompare"  ControlToCompare="Password"
                            ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                            ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="2" style="color: red">
                        <asp:Literal ID="ErrorMessage"  EnableViewState="False"></asp:Literal>
                    </td>
                </tr>
            </table>
            <asp:CheckBox ID="SubscribeCheckBox"  Checked="True" Text="Send me a monthly newsletter." />
            <br />
            <asp:CheckBox ID="ShareInfoCheckBox"  Checked="True" Text="Share my information with partner sites." />
        </ContentTemplate>
    </asp:CreateUserWizardStep>
    
    <asp:CreateUserWizardStep ID="CreateUserWizardStep1" >
        <ContentTemplate>
            <table border="0" style="font-size: 100%; font-family: Verdana">
                <tr>
                    <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                        Sign Up for Your New Account</td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="UserNameLabel"  AssociatedControlID="UserName">
                            User Name:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="UserName" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="UserNameRequired"  ControlToValidate="UserName"
                            ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="PasswordLabel"  AssociatedControlID="Password">
                            Password:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="Password"  TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="PasswordRequired"  ControlToValidate="Password"
                            ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="ConfirmPasswordLabel"  AssociatedControlID="ConfirmPassword">
                            Confirm Password:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="ConfirmPassword"  TextMode="Password"></asp:TextBox>
                        <asp:RequiredFieldValidator ID="ConfirmPasswordRequired"  ControlToValidate="ConfirmPassword"
                            ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
                            ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="EmailLabel"  AssociatedControlID="Email">
                            E-mail:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="Email" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="EmailRequired"  ControlToValidate="Email"
                            ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="QuestionLabel"  AssociatedControlID="Question">
                            Security Question:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="Question" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="QuestionRequired"  ControlToValidate="Question"
                            ErrorMessage="Security question is required." ToolTip="Security question is required."
                            ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="right">
                        <asp:Label ID="AnswerLabel"  AssociatedControlID="Answer">
                            Security Answer:</asp:Label></td>
                    <td>
                        <asp:TextBox ID="Answer" ></asp:TextBox>
                        <asp:RequiredFieldValidator ID="AnswerRequired"  ControlToValidate="Answer"
                            ErrorMessage="Security answer is required." ToolTip="Security answer is required."
                            ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="2">
                        <asp:CompareValidator ID="PasswordCompare"  ControlToCompare="Password"
                            ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                            ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                    </td>
                </tr>
                <tr>
                    <td align="center" colspan="2" style="color: red">
                        <asp:Literal ID="ErrorMessage"  EnableViewState="False"></asp:Literal>
                    </td>
                </tr>
            </table>
            <asp:CheckBox ID="SubscribeCheckBox"  Checked="True" Text="Send me a monthly newsletter." />
            <br />
            <asp:CheckBox ID="ShareInfoCheckBox"  Checked="True" Text="Share my information with partner sites." />
        </ContentTemplate>
    </asp:CreateUserWizardStep>
    
  3. Per personalizzare il passaggio di completamento, creare un elemento <ContentTemplate> nell'elemento <asp:CompleteWizardStep>. Nel modello aggiungere il markup e i controlli per definire il layout e il contenuto dell'interfaccia utente per visualizzare un messaggio di conferma e, se si desidera, consentire all'utente di spostarsi per continuare. Per la creazione di un nuovo account è necessario fornire i controlli per raccogliere le informazioni richieste dal provider di appartenenze. Per informazioni dettagliate, vedere CompleteWizardStep.

    Nell'esempio di codice riportato di seguito viene illustrata una proprietà CompleteStep che fa riferimento ai controlli CheckBox dell'esempio precedente.

    <asp:CompleteWizardStep ID="CompleteWizardStep1" >
        <ContentTemplate>
            <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
                <tr>
                    <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d; height: 18px;">
                        Complete</td>
                </tr>
                <tr>
                    <td>
                        Your account has been successfully created.<br />
                        <br />
                        <asp:Label ID="SubscribeLabel"  Text="You have elected to receive our monthly newsletter."></asp:Label><br />
                        <br />
                        <asp:Label ID="ShareInfoLabel"  Text="You have elected to share your information with partner sites."></asp:Label></td>
                </tr>
                <tr>
                    <td align="right" colspan="2">
                        &nbsp;<asp:Button ID="ContinueButton"  BackColor="#FFFBFF" BorderColor="#CCCCCC"
                            BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue"
                            Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" />
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:CompleteWizardStep>
    
    <asp:CompleteWizardStep ID="CompleteWizardStep1" >
        <ContentTemplate>
            <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
                <tr>
                    <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d; height: 18px;">
                        Complete</td>
                </tr>
                <tr>
                    <td>
                        Your account has been successfully created.<br />
                        <br />
                        <asp:Label ID="SubscribeLabel"  Text="You have elected to receive our monthly newsletter."></asp:Label><br />
                        <br />
                        <asp:Label ID="ShareInfoLabel"  Text="You have elected to share your information with partner sites."></asp:Label></td>
                </tr>
                <tr>
                    <td align="right" colspan="2">
                        &nbsp;<asp:Button ID="ContinueButton"  BackColor="#FFFBFF" BorderColor="#CCCCCC"
                            BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue"
                            Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" />
                    </td>
                </tr>
            </table>
        </ContentTemplate>
    </asp:CompleteWizardStep>
    
  4. Aggiungere codice per fare riferimento ai controlli aggiuntivi. La gestione, ad esempio, dell'evento CreatingUser consente di immettere codice per raccogliere, verificare e modificare le informazioni prima che venga creato un nuovo account utente.

    Nell'esempio di codice riportato di seguito viene illustrato un gestore per l'evento CreatedUser che fa riferimento ai controlli CheckBox degli esempi precedenti e li aggiunge alla proprietà Comment dell'account utente appena creato. Sarà necessario aggiungere un attributo OnCreatedUser al controllo CreateUserWizard nella pagina che fa riferimento al gestore dell'evento CreatedUser, ad esempio OnCreatedUser="CreateUserWizard1_CreatedUser".

    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)
        ' Determine the checkbox values.
        Dim subscribeCheckBox As CheckBox = _
          CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox"), CheckBox)
        Dim shareInfoCheckBox As CheckBox = _
          CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox"), CheckBox)
        Dim userNameTextBox As TextBox = _
          CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)
    
    
        Dim user As MembershipUser = Membership.GetUser(userNameTextBox.Text)
        User.Comment = "Subscribe=" & subscribeCheckBox.Checked.ToString() & "&" & _
                       "ShareInfo=" & shareInfoCheckBox.Checked.ToString()
        Membership.UpdateUser(user)
    
        ' Show or hide the labels based on the checkbox values.
        Dim subscribeLabel As Label = _
          CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel"), Label)
        Dim shareInfoLabel As Label = _
          CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel"), Label)
    
        subscribeLabel.Visible = subscribeCheckBox.Checked
        shareInfoLabel.Visible = shareInfoCheckBox.Checked
    End Sub
    
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
      // Determine the checkbox values.
      CheckBox subscribeCheckBox = 
        (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox");
      CheckBox shareInfoCheckBox =
        (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox");
      TextBox userNameTextBox = 
        (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");
    
      MembershipUser user = Membership.GetUser(userNameTextBox.Text);
      user.Comment = "Subscribe=" + subscribeCheckBox.Checked.ToString() + "&" +
                     "ShareInfo=" + shareInfoCheckBox.Checked.ToString();
      Membership.UpdateUser(user);
    
      // Show or hide the labels based on the checkbox values.
      Label subscribeLabel = 
        (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel");
      Label shareInfoLabel =
        (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel");
    
      subscribeLabel.Visible = subscribeCheckBox.Checked;
      shareInfoLabel.Visible = shareInfoCheckBox.Checked;
    }
    

Per aggiungere un passaggio della procedura guidata

  1. Aggiungere un elemento <asp:WizardStep> alla sezione <WizardSteps> del controllo CreateUserWizard. Nel passaggio aggiuntivo della procedura guidata includere tutti i controlli e il markup che verranno utilizzati dal controllo CreateUserWizard personalizzato.

    Nell'esempio di codice riportato di seguito, ad esempio, viene illustrato un passaggio da aggiungere prima della proprietà CreateUserStep del controllo CreateUserWizard che include un controllo Textbox per l'immissione di un nome utente. Il nome utente verrà controllato per verificare che non sia già presente nel database delle appartenenze.

    <asp:WizardStep ID="CreateUserWizardStep0" >
         <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
              <tr>
                  <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                      Select an Account Name</td>
              </tr>
              <tr>
                  <td>
                    <asp:Label ID="AccountNameLabel"  AssociatedControlID="SearchAccount" > 
                      Account Name:</asp:Label>
                    <asp:TextBox ID="SearchAccount" ></asp:TextBox><br />
                    <asp:Label ID="SearchAccountMessage"  ForeColor="red" />                                          
                  </td>
              </tr>
          </table>
     </asp:WizardStep>
    
    <asp:WizardStep ID="CreateUserWizardStep0" >
         <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
              <tr>
                  <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                      Select an Account Name</td>
              </tr>
              <tr>
                  <td>
                    <asp:Label ID="AccountNameLabel"  AssociatedControlID="SearchAccount" > 
                      Account Name:</asp:Label>
                    <asp:TextBox ID="SearchAccount" ></asp:TextBox><br />
                    <asp:Label ID="SearchAccountMessage"  ForeColor="red" />                                          
                  </td>
              </tr>
          </table>
     </asp:WizardStep>
    
  2. Aggiungere codice per il passaggio della procedura guidata. Per eseguire il codice è possibile gestire l'evento NextButtonClick del controllo Wizard. Il valore della proprietà CurrentStepIndex indica quale passaggio aggiuntivo della procedura guidata ha generato l'evento NextButtonClick in base al numero di indice del passaggio (partendo da 0 per il primo passaggio).

    Nell'esempio di codice riportato di seguito viene illustrato un gestore dell'evento NextButtonClick che accetta il nome utente immesso nel controllo TextBox nel passaggio della procedura guidata dell'esempio di codice precedente e verifica che il nome utente sia stato specificato e non sia attualmente presente nel database delle appartenenze. Sarà necessario aggiungere un attributo OnNextButtonClick al controllo CreateUserWizard nella pagina che fa riferimento al gestore del gestore eventi NextButtonClick, ad esempio OnNextButtonClick="CreateUserWizard1_NextButtonClick".

    Private Function UserExists(ByVal username As String) As Boolean
        If Membership.GetUser(username) IsNot Nothing Then Return True
    
        Return False
    End Function
    
    Protected Sub CreateUserWizard1_NextButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
        If e.CurrentStepIndex = 0 Then
            If SearchAccount.Text.Trim() = "" OrElse UserExists(SearchAccount.Text) Then
                SearchAccountMessage.Text = "That account already exists. Please select an different account name."
                e.Cancel = True
            Else
                Dim userName As TextBox = _
                  CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"), TextBox)
                userName.Text = SearchAccount.Text
                SearchAccountMessage.Text = ""
                e.Cancel = False
            End If
        End If
    End Sub
    
    private bool UserExists(string username)
    {
        if (Membership.GetUser(username) != null) { return true; }
    
        return false;
    }
    
    protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
    {
        if (e.CurrentStepIndex == 0)
        {
            if (SearchAccount.Text.Trim() == "" || UserExists(SearchAccount.Text))
            {
                SearchAccountMessage.Text = "That account already exists. Please select an different account name.";
                e.Cancel = true;
            }
            else
            {
                TextBox userName =
                  (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
                userName.Text = SearchAccount.Text;
                SearchAccountMessage.Text = "";
                e.Cancel = false;
            }
        }
    }
    
    Nota sulla sicurezza:

    Il controllo include una casella di testo che accetta l'input dell'utente e rappresenta quindi una potenziale minaccia alla sicurezza. Per impostazione predefinita, le pagine Web ASP.NET verificano che l'input dell'utente non includa script o elementi HTML. Per ulteriori informazioni, vedere Cenni preliminari sugli attacchi tramite script.

Esempio

Nell'esempio di codice riportato di seguito viene illustrato un controllo CreateUserWizard con modelli definiti per i due passaggi di base, CreateUserStep e CompleteStep, e un passaggio aggiuntivo della procedura guidata aggiunto prima di CreateUserStep.

Nota sulla sicurezza:

Il controllo include una casella di testo che accetta l'input dell'utente e rappresenta quindi una potenziale minaccia alla sicurezza. L'input dell'utente in una pagina Web potrebbe infatti contenere script client dannosi. Per impostazione predefinita, le pagine Web ASP.NET verificano che l'input dell'utente non includa script o elementi HTML. Se questa convalida è attivata, non occorrerà effettuare un controllo esplicito per escludere che l'input utente contenga script o elementi HTML. Per ulteriori informazioni, vedere Cenni preliminari sugli attacchi tramite script.

<%@ Page Language="VB" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script >
    Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As EventArgs)
        ' Determine the checkbox values.
        Dim subscribeCheckBox As CheckBox = _
          CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox"), CheckBox)
        Dim shareInfoCheckBox As CheckBox = _
          CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox"), CheckBox)
        Dim userNameTextBox As TextBox = _
          CType(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox)


        Dim user As MembershipUser = Membership.GetUser(userNameTextBox.Text)
        User.Comment = "Subscribe=" & subscribeCheckBox.Checked.ToString() & "&" & _
                       "ShareInfo=" & shareInfoCheckBox.Checked.ToString()
        Membership.UpdateUser(user)

        ' Show or hide the labels based on the checkbox values.
        Dim subscribeLabel As Label = _
          CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel"), Label)
        Dim shareInfoLabel As Label = _
          CType(CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel"), Label)

        subscribeLabel.Visible = subscribeCheckBox.Checked
        shareInfoLabel.Visible = shareInfoCheckBox.Checked
    End Sub

    Private Function UserExists(ByVal username As String) As Boolean
        If Membership.GetUser(username) IsNot Nothing Then Return True

        Return False
    End Function

    Protected Sub CreateUserWizard1_NextButtonClick(ByVal sender As Object, ByVal e As WizardNavigationEventArgs)
        If e.CurrentStepIndex = 0 Then
            If SearchAccount.Text.Trim() = "" OrElse UserExists(SearchAccount.Text) Then
                SearchAccountMessage.Text = "That account already exists. Please select an different account name."
                e.Cancel = True
            Else
                Dim userName As TextBox = _
                  CType(CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName"), TextBox)
                userName.Text = SearchAccount.Text
                SearchAccountMessage.Text = ""
                e.Cancel = False
            End If
        End If
    End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" >
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" >
    <div>
        <asp:CreateUserWizard ID="CreateUserWizard1"  BackColor="#F7F6F3" BorderColor="#E6E2D8"
            BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" 
            OnNextButtonClick="CreateUserWizard1_NextButtonClick"
            OnCreatedUser="CreateUserWizard1_CreatedUser" ContinueDestinationPageUrl="~/Default.aspx">
            <WizardSteps>
               <asp:WizardStep ID="CreateUserWizardStep0" >
                    <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
                         <tr>
                             <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                                 Select an Account Name</td>
                         </tr>
                         <tr>
                             <td>
                               <asp:Label ID="AccountNameLabel"  AssociatedControlID="SearchAccount" > 
                                 Account Name:</asp:Label>
                               <asp:TextBox ID="SearchAccount" ></asp:TextBox><br />
                               <asp:Label ID="SearchAccountMessage"  ForeColor="red" />                                          
                             </td>
                         </tr>
                     </table>
                </asp:WizardStep>
                <asp:CreateUserWizardStep ID="CreateUserWizardStep1" >
                    <ContentTemplate>
                        <table border="0" style="font-size: 100%; font-family: Verdana">
                            <tr>
                                <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                                    Sign Up for Your New Account</td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="UserNameLabel"  AssociatedControlID="UserName">
                                        User Name:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="UserName" ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="UserNameRequired"  ControlToValidate="UserName"
                                        ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="PasswordLabel"  AssociatedControlID="Password">
                                        Password:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="Password"  TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="PasswordRequired"  ControlToValidate="Password"
                                        ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="ConfirmPasswordLabel"  AssociatedControlID="ConfirmPassword">
                                        Confirm Password:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="ConfirmPassword"  TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="ConfirmPasswordRequired"  ControlToValidate="ConfirmPassword"
                                        ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
                                        ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="EmailLabel"  AssociatedControlID="Email">
                                        E-mail:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="Email" ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="EmailRequired"  ControlToValidate="Email"
                                        ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="QuestionLabel"  AssociatedControlID="Question">
                                        Security Question:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="Question" ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="QuestionRequired"  ControlToValidate="Question"
                                        ErrorMessage="Security question is required." ToolTip="Security question is required."
                                        ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="AnswerLabel"  AssociatedControlID="Answer">
                                        Security Answer:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="Answer" ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="AnswerRequired"  ControlToValidate="Answer"
                                        ErrorMessage="Security answer is required." ToolTip="Security answer is required."
                                        ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2">
                                    <asp:CompareValidator ID="PasswordCompare"  ControlToCompare="Password"
                                        ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                                        ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color: red">
                                    <asp:Literal ID="ErrorMessage"  EnableViewState="False"></asp:Literal>
                                </td>
                            </tr>
                        </table>
                        <asp:CheckBox ID="SubscribeCheckBox"  Checked="True" Text="Send me a monthly newsletter." />
                        <br />
                        <asp:CheckBox ID="ShareInfoCheckBox"  Checked="True" Text="Share my information with partner sites." />
                    </ContentTemplate>
                </asp:CreateUserWizardStep>
                <asp:CompleteWizardStep ID="CompleteWizardStep1" >
                    <ContentTemplate>
                        <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
                            <tr>
                                <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d; height: 18px;">
                                    Complete</td>
                            </tr>
                            <tr>
                                <td>
                                    Your account has been successfully created.<br />
                                    <br />
                                    <asp:Label ID="SubscribeLabel"  Text="You have elected to receive our monthly newsletter."></asp:Label><br />
                                    <br />
                                    <asp:Label ID="ShareInfoLabel"  Text="You have elected to share your information with partner sites."></asp:Label></td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    &nbsp;<asp:Button ID="ContinueButton"  BackColor="#FFFBFF" BorderColor="#CCCCCC"
                                        BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue"
                                        Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" />
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:CompleteWizardStep>
            </WizardSteps>
            <SideBarStyle BackColor="#5D7B9D" BorderWidth="0px" Font-Size="0.9em" VerticalAlign="Top" />
            <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <SideBarButtonStyle BorderWidth="0px" Font-Names="Verdana" ForeColor="White" />
            <NavigationButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
                BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
            <HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" Font-Bold="True" Font-Size="0.9em"
                ForeColor="White" HorizontalAlign="Center" />
            <CreateUserButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
                BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
            <ContinueButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
                BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
            <StepStyle BorderWidth="0px" />
        </asp:CreateUserWizard>
        &nbsp;</div>
    </form>
</body>
</html>
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script >
  protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
  {
    // Determine the checkbox values.
    CheckBox subscribeCheckBox = 
      (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox");
    CheckBox shareInfoCheckBox =
      (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox");
    TextBox userNameTextBox = 
      (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");

    MembershipUser user = Membership.GetUser(userNameTextBox.Text);
    user.Comment = "Subscribe=" + subscribeCheckBox.Checked.ToString() + "&" +
                   "ShareInfo=" + shareInfoCheckBox.Checked.ToString();
    Membership.UpdateUser(user);

    // Show or hide the labels based on the checkbox values.
    Label subscribeLabel = 
      (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel");
    Label shareInfoLabel =
      (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel");

    subscribeLabel.Visible = subscribeCheckBox.Checked;
    shareInfoLabel.Visible = shareInfoCheckBox.Checked;
  }

  private bool UserExists(string username)
  {
      if (Membership.GetUser(username) != null) { return true; }

      return false;
  }

  protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
  {
      if (e.CurrentStepIndex == 0)
      {
          if (SearchAccount.Text.Trim() == "" || UserExists(SearchAccount.Text))
          {
              SearchAccountMessage.Text = "That account already exists. Please select an different account name.";
              e.Cancel = true;
          }
          else
          {
              TextBox userName =
                (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
              userName.Text = SearchAccount.Text;
              SearchAccountMessage.Text = "";
              e.Cancel = false;
          }
      }
  }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" >
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" >
    <div>
        <asp:CreateUserWizard ID="CreateUserWizard1"  BackColor="#F7F6F3" BorderColor="#E6E2D8"
            BorderStyle="Solid" BorderWidth="1px" Font-Names="Verdana" Font-Size="0.8em" 
            OnNextButtonClick="CreateUserWizard1_NextButtonClick"
            OnCreatedUser="CreateUserWizard1_CreatedUser" ContinueDestinationPageUrl="~/Default.aspx">
            <WizardSteps>
               <asp:WizardStep ID="CreateUserWizardStep0" >
                    <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
                         <tr>
                             <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                                 Select an Account Name</td>
                         </tr>
                         <tr>
                             <td>
                               <asp:Label ID="AccountNameLabel"  AssociatedControlID="SearchAccount" > 
                                 Account Name:</asp:Label>
                               <asp:TextBox ID="SearchAccount" ></asp:TextBox><br />
                               <asp:Label ID="SearchAccountMessage"  ForeColor="red" />                                          
                             </td>
                         </tr>
                     </table>
                </asp:WizardStep>
                <asp:CreateUserWizardStep ID="CreateUserWizardStep1" >
                    <ContentTemplate>
                        <table border="0" style="font-size: 100%; font-family: Verdana">
                            <tr>
                                <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d">
                                    Sign Up for Your New Account</td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="UserNameLabel"  AssociatedControlID="UserName">
                                        User Name:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="UserName" ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="UserNameRequired"  ControlToValidate="UserName"
                                        ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="PasswordLabel"  AssociatedControlID="Password">
                                        Password:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="Password"  TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="PasswordRequired"  ControlToValidate="Password"
                                        ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="ConfirmPasswordLabel"  AssociatedControlID="ConfirmPassword">
                                        Confirm Password:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="ConfirmPassword"  TextMode="Password"></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="ConfirmPasswordRequired"  ControlToValidate="ConfirmPassword"
                                        ErrorMessage="Confirm Password is required." ToolTip="Confirm Password is required."
                                        ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="EmailLabel"  AssociatedControlID="Email">
                                        E-mail:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="Email" ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="EmailRequired"  ControlToValidate="Email"
                                        ErrorMessage="E-mail is required." ToolTip="E-mail is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="QuestionLabel"  AssociatedControlID="Question">
                                        Security Question:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="Question" ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="QuestionRequired"  ControlToValidate="Question"
                                        ErrorMessage="Security question is required." ToolTip="Security question is required."
                                        ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="right">
                                    <asp:Label ID="AnswerLabel"  AssociatedControlID="Answer">
                                        Security Answer:</asp:Label></td>
                                <td>
                                    <asp:TextBox ID="Answer" ></asp:TextBox>
                                    <asp:RequiredFieldValidator ID="AnswerRequired"  ControlToValidate="Answer"
                                        ErrorMessage="Security answer is required." ToolTip="Security answer is required."
                                        ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2">
                                    <asp:CompareValidator ID="PasswordCompare"  ControlToCompare="Password"
                                        ControlToValidate="ConfirmPassword" Display="Dynamic" ErrorMessage="The Password and Confirmation Password must match."
                                        ValidationGroup="CreateUserWizard1"></asp:CompareValidator>
                                </td>
                            </tr>
                            <tr>
                                <td align="center" colspan="2" style="color: red">
                                    <asp:Literal ID="ErrorMessage"  EnableViewState="False"></asp:Literal>
                                </td>
                            </tr>
                        </table>
                        <asp:CheckBox ID="SubscribeCheckBox"  Checked="True" Text="Send me a monthly newsletter." />
                        <br />
                        <asp:CheckBox ID="ShareInfoCheckBox"  Checked="True" Text="Share my information with partner sites." />
                    </ContentTemplate>
                </asp:CreateUserWizardStep>
                <asp:CompleteWizardStep ID="CompleteWizardStep1" >
                    <ContentTemplate>
                        <table border="0" style="font-size: 100%; font-family: Verdana" id="TABLE1" >
                            <tr>
                                <td align="center" colspan="2" style="font-weight: bold; color: white; background-color: #5d7b9d; height: 18px;">
                                    Complete</td>
                            </tr>
                            <tr>
                                <td>
                                    Your account has been successfully created.<br />
                                    <br />
                                    <asp:Label ID="SubscribeLabel"  Text="You have elected to receive our monthly newsletter."></asp:Label><br />
                                    <br />
                                    <asp:Label ID="ShareInfoLabel"  Text="You have elected to share your information with partner sites."></asp:Label></td>
                            </tr>
                            <tr>
                                <td align="right" colspan="2">
                                    &nbsp;<asp:Button ID="ContinueButton"  BackColor="#FFFBFF" BorderColor="#CCCCCC"
                                        BorderStyle="Solid" BorderWidth="1px" CausesValidation="False" CommandName="Continue"
                                        Font-Names="Verdana" ForeColor="#284775" Text="Continue" ValidationGroup="CreateUserWizard1" />
                                </td>
                            </tr>
                        </table>
                    </ContentTemplate>
                </asp:CompleteWizardStep>
            </WizardSteps>
            <SideBarStyle BackColor="#5D7B9D" BorderWidth="0px" Font-Size="0.9em" VerticalAlign="Top" />
            <TitleTextStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <SideBarButtonStyle BorderWidth="0px" Font-Names="Verdana" ForeColor="White" />
            <NavigationButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
                BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
            <HeaderStyle BackColor="#5D7B9D" BorderStyle="Solid" Font-Bold="True" Font-Size="0.9em"
                ForeColor="White" HorizontalAlign="Center" />
            <CreateUserButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
                BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
            <ContinueButtonStyle BackColor="#FFFBFF" BorderColor="#CCCCCC" BorderStyle="Solid"
                BorderWidth="1px" Font-Names="Verdana" ForeColor="#284775" />
            <StepStyle BorderWidth="0px" />
        </asp:CreateUserWizard>
        &nbsp;</div>
    </form>
</body>
</html>

Vedere anche

Concetti

Personalizzazione dell'aspetto dei controlli di accesso ASP.NET

Cenni preliminari su temi e interfacce ASP.NET

Riferimenti

Cenni preliminari sui controlli di accesso di ASP.NET

TemplatedWizardStep