Reputation: 1602
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?
Upvotes: 0
Views: 1622
Reputation: 710
You have to get to the wizard step first before you can access the control
if (Wizard1.ActiveStep.Title == "Specify Roles")
{
CheckBox RoleList = RegisterUserWithRoles.ActiveStep.FindControl("RoleList") as CheckBox;
}
I found this here: http://forums.asp.net/t/1265377.aspx/1
Upvotes: 0
Reputation: 81
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>
Upvotes: 1