我在我的 registeruser 代码中添加了一个下拉列表,以便我可以从我们的数据库中随机加载安全问题。
这是该代码;
<asp:CreateUserWizard ID="RegisterUser" runat="server" EnableViewState="false"
CancelDestinationPageUrl="RegistrationFailed.aspx" DisableCreatedUser="true"
ContinueDestinationPageUrl="Login.aspx" LoginCreatedUser="false">
<LayoutTemplate>
<asp:PlaceHolder ID="wizardStepPlaceholder" runat="server"></asp:PlaceHolder>
<asp:PlaceHolder ID="navigationPlaceholder" runat="server"></asp:PlaceHolder>
</LayoutTemplate>
<WizardSteps>
<asp:CreateUserWizardStep ID="RegisterUserWizardStep" runat="server">
<ContentTemplate>
<span class="failureNotification">
<asp:Literal ID="ErrorMessage" runat="server"></asp:Literal>
</span>
<asp:ValidationSummary ID="RegisterUserValidationSummary" runat="server" CssClass="failureNotification"
ValidationGroup="RegisterUserValidationGroup"/>
<div class="accountInfo">
<fieldset class="register">
<legend>Account Information</legend>
'All other fields removed for brevity
<p>
<asp:Label ID="QuestionLabel" runat="server" AssociatedControlID="Question">Select Security Question:</asp:Label>
<asp:DropDownList ID="Question" runat="server">
</asp:DropDownList><br />
<i style="font-size: .7em;">If you forget your password you will be asked the security question you choose here and prompted to enter the answer you specify below.</i>
<asp:RequiredFieldValidator ID="rfvSecurityQuestion" runat="server" ControlToValidate="Question"
CssClass="failureNotification" ErrorMessage="« [Required]" ToolTip="A security question is required."
ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
<p>
<asp:Label ID="Answerlabel" runat="server" AssociatedControlID="Answer">Security Answer:</asp:Label>
<asp:TextBox ID="Answer" runat="server" CssClass="textEntry"></asp:TextBox>
<asp:RequiredFieldValidator ID="AnswerRequired" runat="server" ControlToValidate="Answer"
CssClass="failureNotification" ErrorMessage="« [Required]" ToolTip="Security answer is required."
ValidationGroup="RegisterUserValidationGroup">*</asp:RequiredFieldValidator>
</p>
</fieldset>
<p class="submitButton">
<asp:Button ID="CreateUserButton" runat="server" CommandName="MoveNext" Text="Create User"
ValidationGroup="RegisterUserValidationGroup" CssClass="buttons" />
</p>
</div>
</ContentTemplate>
<CustomNavigationTemplate>
</CustomNavigationTemplate>
</asp:CreateUserWizardStep>
</WizardSteps>
</asp:CreateUserWizard>
我正在尝试在后面的代码中将项目添加到该下拉列表中。智能感知没有看到任何带有问题 ID 的控件,但找到了 RegisterUser.Question,但我无法向其中添加列表项。
Protected Sub Page_PreLoad(sender As Object, e As EventArgs) Handles Me.PreLoad
Dim ddl As DropDownList = TryCast(FindControl(RegisterUser.Question), DropDownList)
'If ddl Is Nothing Then MsgBox("nothing") ' for testing if ddl is found
'Dim itemlist As New List(Of String)
'itemlist = GetSecurityQuestionsforDDL()
'For Each item As String In itemlist
ddl.Items.Add(New ListItem("did this get added?"))
'Next
End Sub
页面加载,但下拉列表中没有问题。如何找到下拉控件以向其中添加列表项?