2011-04-16 46 views
3
<asp:LoginView ID="LoginView4" runat="server"> 
     <AnonymousTemplate> 

     <asp:DropShadowExtender ID="DropShadowExtender3" runat="server" 
           TargetControlID="Panel3" 
           Opacity=".38" 
           Rounded="true"> 
       </asp:DropShadowExtender> 
       <asp:Panel ID="Panel3" runat="server" 
            BackColor="Silver" Width="400px"> 

       <asp:CreateUserWizard ID="CreateUserWizard1" 
            runat="server" 
            ContinueDestinationPageUrl="~/ViewCart_aspx/ViewCart.aspx" 
         oncreateduser="CreateUserWizard1_CreatedUser"> 


       <WizardSteps> 
        <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" > 
         <ContentTemplate> 
         <fieldset class="push"> 
          <table border="0"> 
           <tr> 
            <td align="center" colspan="2"> 
             <h3 style="text-align:center;">Sign Up for Your New Account</h3></td> 
           </tr> 
           <tr> 
            <td align="right"> 
             <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">User Name:</asp:Label> 
            </td> 
            <td>&nbsp; 
             **<asp:TextBox ID="UserName" runat="server" Width="150px"></asp:TextBox>** 
             <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" 
              ControlToValidate="UserName" ErrorMessage="User Name is required." 
              ToolTip="User Name is required." ValidationGroup="CreateUserWizard1">*</asp:RequiredFieldValidator> 
            </td> 

我使用此代码,找到控制如何找到控件?

Protected Sub CreateUserWizard1_CreatedUser(ByVal sender As Object, ByVal e As System.EventArgs) 
    Dim UserNameTextBox As TextBox = DirectCast(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox) 
    Roles.AddUserToRole(UserNameTextBox.Text, "User") 

End Sub 

,但它给了我

错误 “错误12名 'CreateUserWizardStep1' 未声明”。

回答

0

您必须首先在LoginView上使用FindControl()来引用CreateUserWizardStep1

Dim CreateUserWizardStep1 As CreateUserWizard = 
    DirectCast(LoginView4.FindControl("CreateUserWizard1"), CreateUserWizard) 

,然后你可以做

If CreateUserWizardStep1 IsNot Nothing 

    Dim UserNameTextBox As TextBox = DirectCast(CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName"), TextBox) 
     Roles.AddUserToRole(UserNameTextBox.Text, "User") 
End If