【问题标题】:How can I find a Control inside WizardStep?如何在 WizardStep 中找到控件?
【发布时间】:2013-07-08 16:37:43
【问题描述】:

我正在使用 CreateWizardStep 为我的站点创建用户...我添加了新步骤并在步骤中放置了一个 CheckBoxList,但我正在尝试搜索此控件但它返回空引用错误,代码下方剪辑:

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();

如何在 StepWizard 中找到这个 CheckBoxList 控件?

【问题讨论】:

    标签: c# asp.net findcontrol


    【解决方案1】:

    它可能为 null,因为 as 关键字正在尝试将复选框转换为复选框列表,但未能成功。

    尝试将 RoleList 更改为 &lt;asp:CheckBoxList ID="RoleList" runat="server"&gt; &lt;/asp:CheckBoxList&gt;

    【讨论】:

    • 非常感谢!我相信我可以将复选框转换为复选框列表......但现在我发现它不可能做到这一点......
    【解决方案2】:

    您必须先进入向导步骤,然后才能访问控件

    if (Wizard1.ActiveStep.Title == "Specify Roles")
            {
                CheckBox RoleList = RegisterUserWithRoles.ActiveStep.FindControl("RoleList") as CheckBox;
    
            }
    

    我在这里找到了这个: http://forums.asp.net/t/1265377.aspx/1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-14
      • 1970-01-01
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      • 2016-12-09
      相关资源
      最近更新 更多