【问题标题】:asp.net create uzer wizard getting a handle on controls in custom stepsasp.net 创建 uzer 向导在自定义步骤中处理控件
【发布时间】:2013-03-12 01:39:28
【问题描述】:

我在我的 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>

我已成功导航到新步骤

protected void NewUserprofileWizard_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
    if (NewUserprofileWizard.ActiveStepIndex == 0)
    {
        NewUserprofileWizard.ActiveStepIndex = 1;

    }
}

但我无法从我的代码隐藏中访问下拉列表 注意:我可以在第一步(创建用户)中获得控件的句柄。

但下一步中的任何控件总是返回 null。

这是我正在使用的代码

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

我总是返回一个空值。

请注意,这很好用

TextBox tmp = (TextBox)NewUserprofileWizard.CreateUserStep.ContentTemplateContainer.FindControl("Email");
    userProfile.AccountEmail = tmp.Text;

问题似乎是自定义步骤所独有的

感谢您的帮助


尝试了 Gregors 的建议。没运气。我的总是显示为空。

如果这有帮助: 我的向导在用户控件中.. 使用用户控件的页面位于母版页内.....

【问题讨论】:

    标签: asp.net webforms asp.net-membership


    【解决方案1】:

    这是我为您创建的小示例,第一个 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>
    

    现在找到第一个下拉列表的代码:

        protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
        {
            if (e.CurrentStepIndex == 0)
            {
                //get instance to dropdown...
                string selectedValue = null;
                string controlId = null;
                foreach (var item in CreateUserWizard1.WizardSteps[0].Controls)
                {
                    DropDownList ddl = item as DropDownList;
                    if (ddl != null)
                    {
                        selectedValue = ddl.SelectedValue;
                        controlId = ddl.ClientID;
                        break;
                    }
                }       
            }
        }
    

    当然你也可以像这样找到你的下拉菜单:

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

    编码愉快!

    【讨论】:

    • 感谢 gregor。但控制列表中始终包含 null 。查看我添加到帖子中的图片
    • 请从您的 aspx 代码中删除 ContentTemplate 并重试。有关更多详细信息,请检查我的示例中的 aspx 结构。
    • 抱歉回复晚了。我不能只删除内容模板。如果我做我的aspx 不会呈现。它给出了关于 TemplatedWizardStep 没有名为 的公共属性的错误
    【解决方案2】:

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

    因为我在模板向导步骤中,所以我必须将向导步骤转换为模板向导步骤。

    从这里我现在可以找到控件。哇哦!

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

    感谢大家的帮助

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-08-07
      • 2012-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-19
      • 1970-01-01
      相关资源
      最近更新 更多