I'm using the CreateWizardStep for create user to my site... I added new step and inside the step a put a CheckBoxList, but I'm trying to search this control but it return null reference error, below a code snip:
ASPX
<asp:CreateUserWizard ID="RegisterUserWithRoles" runat="server" ContinueDestinationPageUrl="~/Default.aspx" LoginCreatedUser="False" OnActiveStepChanged="RegisterUserWithRoles_ActiveStepChanged" ActiveStepIndex="1">
<WizardSteps>
<asp:CreateUserWizardStep runat="server" />
<asp:WizardStep ID="SpecifyRolesStep" runat="server" AllowReturn="False" StepType="Step" Title="Specify Roles">
<asp:CheckBox ID="RoleList" runat="server" />
</asp:WizardStep>
<asp:CompleteWizardStep runat="server" />
</WizardSteps>
</asp:CreateUserWizard>
C#
// Reference the SpecifyRolesStep WizardStep .
WizardStep SpecifyRolesStep = RegisterUserWithRoles.FindControl("SpecifyRolesStep") as WizardStep;
// Reference the RoleList CheckBoxList
CheckBoxList RoleList = SpecifyRolesStep.FindControl("RoleList") as CheckBoxList;
// Bind the set of roles to RoleList
RoleList.DataSource = System.Web.Security.Roles.GetAllRoles();
RoleList.DataBind();
How can I find this CheckBoxList Control inside the StepWizard?
It might be null because the as
keyword is trying and failing to cast a checkbox as a checkboxlist.
Try changing the RoleList to <asp:CheckBoxList ID="RoleList" runat="server"> </asp:CheckBoxList>