开发者

how to find the control?

开发者 https://www.devze.com 2023-02-25 19:54 出处:网络
<asp:LoginView ID=\"LoginView4\" runat=\"server\"> <AnonymousTemplate> <asp:DropShadowExtender ID=\"DropShadowExtender3\" runat=\"server\"
<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="UserN开发者_Python百科ame">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>

I am using this code to find the control

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

but it gives me an error

"Error 12 Name 'CreateUserWizardStep1' is not declared."


You'll have to use FindControl() on LoginView to reference CreateUserWizardStep1 first.

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

and then you can do

If CreateUserWizardStep1 IsNot Nothing 

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

精彩评论

暂无评论...
验证码 换一张
取 消