asp.net创建uzer向导在自定义步骤中获取控件句柄

asp.net创建uzer向导在自定义步骤中获取控件句柄,asp.net,webforms,asp.net-membership,Asp.net,Webforms,Asp.net Membership,我为我的uzerwizard添加了一个额外的步骤 <asp:TemplatedWizardStep id="stpPayment" runat="server" Title="Payment"> <ContentTemplate> <asp:DropDownList ID="cmbSubs" runat="server" ClientIDMode="Static" Width="200px"&

我为我的uzerwizard添加了一个额外的步骤

<asp:TemplatedWizardStep id="stpPayment" runat="server" Title="Payment">
        <ContentTemplate>
<asp:DropDownList ID="cmbSubs" runat="server" ClientIDMode="Static" 
                            Width="200px">

                            <asp:ListItem Value="month">Monthly Subscription</asp:ListItem>
                            <asp:ListItem Value="year">Annual Subscription</asp:ListItem>
                        </asp:DropDownList>
但是我无法从我的codebehind访问dropdownlist 注意:我可以在第一步(createuser)中获得控件的句柄

但是下一步中的任何控件都会返回null

这是我正在使用的代码

DropDownList cmb = (DropDownList)NewUserprofileWizard.WizardSteps[1].FindControl("cmbSubs");
我总是返回空值

请注意,这一切都很好

TextBox tmp = (TextBox)NewUserprofileWizard.CreateUserStep.ContentTemplateContainer.FindControl("Email");
    userProfile.AccountEmail = tmp.Text;
这个问题似乎是自定义步骤所独有的

谢谢你的帮助


他尝试了格雷戈里的建议。不走运。我的总是空的

如果thsi有任何帮助: 我的向导位于用户控件内。。
使用用户控件的页面位于母版页内。…

以下是我为您创建的小示例,第一个aspx代码:

        <asp:CreateUserWizard ID="CreateUserWizard1" runat="server" OnNextButtonClick="CreateUserWizard1_NextButtonClick">
            <WizardSteps>
                <asp:WizardStep runat="server" Title="My Custom Step">
                    <asp:DropDownList ID="cmbSubs" runat="server" ClientIDMode="Static"
                        Width="200px">
                        <asp:ListItem Value="month">Monthly Subscription</asp:ListItem>
                        <asp:ListItem Value="year">Annual Subscription</asp:ListItem>
                    </asp:DropDownList>
                </asp:WizardStep>
                <asp:CreateUserWizardStep runat="server" />
                <asp:CompleteWizardStep runat="server" />
            </WizardSteps>
        </asp:CreateUserWizard>
当然,您也可以找到如下下拉列表:

DropDownList cmbSubs = CreateUserWizard1.WizardSteps[0].FindControl("cmbSubs") as DropDownList;

快乐编码

看来今天我的google foo做得好多了

因为我在templateswizardstep中,所以我必须将向导步骤强制转换为templatedwizardstep

从这里我现在可以找到控制。呜呜

TemplatedWizardStep step = (TemplatedWizardStep)NewUserprofileWizard.WizardSteps[1];
cmb = (DropDownList)step.ContentTemplateContainer.FindControl("cmbSubs"); 

谢谢大家的帮助

谢谢格雷戈。但是控件lisst中始终包含null。请参阅我添加到postPlease中的图像从您的aspx代码中删除ContentTemplate,然后重试。有关更多详细信息,请查看我的示例中的aspx结构。对于迟交的答复,我深表歉意。我不能只是删除内容模板。如果我这样做,我的aspx不会渲染。它给出了一个关于TemplatedWizardStep没有名为的公共属性的错误
DropDownList cmbSubs = CreateUserWizard1.WizardSteps[0].FindControl("cmbSubs") as DropDownList;
TemplatedWizardStep step = (TemplatedWizardStep)NewUserprofileWizard.WizardSteps[1];
cmb = (DropDownList)step.ContentTemplateContainer.FindControl("cmbSubs");