3

我正在尝试从 ddlMake 下拉列表中触发 SelectedIndexChanged,但该事件未触发,如果我将 ddlMake 移到 CreateUserWizard 之外,它将起作用。我做错什么了吗:

  <asp:CreateUserWizard runat="server" ID="RegisterUser" ViewStateMode="Disabled" OnCreatingUser="RegisterUser_CreatingUser" OnCreatedUser="RegisterUser_CreatedUser" >
             <LayoutTemplate>
                 <asp:PlaceHolder runat="server" ID="wizardStepPlaceholder" />
                 <asp:PlaceHolder runat="server" ID="navigationPlaceholder" />
             </LayoutTemplate>
             <WizardSteps>
                 <asp:CreateUserWizardStep runat="server" ID="CreateUserWizardStep1">
                     <ContentTemplate>
                         <p class="message-info">
                             Passwords are required to be a minimum of <%: Membership.MinRequiredPasswordLength %> characters in length.
                         </p>
                         <p class="validation-summary-errors">
                             <asp:Literal runat="server" ID="ErrorMessage" />
                         </p>
                         <div class="row-fluid MT35">
                             <div class="span3">User ID:</div>
                             <div class="span8">
                                 <asp:TextBox runat="server" ID="UserName" />
                                 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="UserName"
                                     CssClass="field-validation-error"
                                     ErrorMessage="The user name field is required." Display="Dynamic" />
                                 <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" Text="Username length must be between 5 to 12 characters without spacing."
                                     ControlToValidate="UserName" SetFocusOnError="true"
                                     ValidationExpression="^[a-zA-Z0-9'@&#_]{5,12}$" Display="Dynamic" />
                             </div>
                             <div class="row-fluid ">
                                 <div class="span3">Password:</div>
                                 <div class="span8">
                                     <asp:TextBox runat="server" ID="Password" TextMode="Password" />
                                     <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="Password"
                                         CssClass="field-validation-error" ErrorMessage="The password field is required." />
                                 </div>
                                 <div class="row-fluid ">
                                     <div class="span3">Confirm Password:</div>
                                     <div class="span8">
                                         <asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password" />
                                         <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="ConfirmPassword"
                                             CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The confirm password field is required." />
                                         <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="Password" ControlToValidate="ConfirmPassword"
                                             CssClass="field-validation-error" Display="Dynamic" ErrorMessage="The password and confirmation password do not match." />
                                     </div>
                                 </div>

                                 <div class="row-fluid MT35">
                                     <div class="span3">Your Car:</div>
                                     <div class="span8 YourCarInformation">
                                     <asp:DropDownList ID="ddlCarMake" OnSelectedIndexChanged="ddlMake_SelectedIndexChanged" AutoPostBack="True" runat="server" CssClass="span12"></asp:DropDownList>
                                     <asp:DropDownList ID="ddlCarModel" runat="server" CssClass="span12"></asp:DropDownList>
                                     <asp:TextBox ID="txtRegistration" CssClass="pull-left" runat="server" placeholder="registration date dd/mm/yyyy"></asp:TextBox>
                                 </div>
                                     </div>
                                 </div>
                                 <div class="row-fluid">
                                     <div class="span3">Recieve Newsletter:</div>
                                     <div class="span8 RadioBtn">
                                         <label class="radio">
                                             <asp:RadioButtonList ID="rbNewsLetter" runat="server" RepeatDirection="Horizontal">
                                                 <asp:ListItem Text="Yes" Value="true" Selected="True" />
                                                 <asp:ListItem Text="No" Value="false" />
                                             </asp:RadioButtonList>
                                         </label>
                                     </div>
                                 </div>
                             </div>
                         </div>
                     </ContentTemplate>
                     <CustomNavigationTemplate />
                 </asp:CreateUserWizardStep>
             </WizardSteps>
         </asp:CreateUserWizard>

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            RegisterUser.ContinueDestinationPageUrl = Request.QueryString["ReturnUrl"];

            DropDownList ddlCarMake =
                (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCarMake");
            DropDownList ddlCarModel =
                (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCarModel");

            ddlCarMake.DataSource = ds.Tables[0];
            ddlCarMake.DataTextField = "CarMake";
            ddlCarMake.DataValueField = "CarMake";
            ddlCarMake.DataBind();
            ddlCarMake.Items.Insert(0, new ListItem("Any", ""));
            ddlCarMake.Items.Insert(ds.Tables[0].Rows.Count + 1, new ListItem("Others", "Others"));

            ddlCarModel.Items.Insert(0, new ListItem("Any", ""));
        }
    }

protected void ddlMake_SelectedIndexChanged(object sender, EventArgs e)
{
    VehicleBLL vehicleBll = new VehicleBLL();

    DropDownList ddlCarMake = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCarMake");
    DropDownList ddlCarModel = (DropDownList)CreateUserWizardStep1.ContentTemplateContainer.FindControl("ddlCarModel");

    DataSet ds = null;
    if (ddlCarMake.SelectedIndex != 0)
    {
        ds = vehicleBll.GetCarModel(ddlCarMake.SelectedValue);

        ddlCarModel.DataSource = ds.Tables[0];
        ddlCarModel.DataTextField =  "CarModel";
        ddlCarModel.DataValueField = "CarModel";
        ddlCarModel.DataBind();

        ddlCarModel.Items.Insert(0, new ListItem("Any", ""));
    }
}
4

2 回答 2

3

好的,半天过去了,找到答案,去掉CreateUserWizard控件中的ViewStateMode="Disabled",一切正常。

于 2013-08-26T16:19:09.073 回答
-1

我认为您必须首先将下拉列表放在更新面板中,然后将自动回发在下拉列表属性中设置为 true,这将解决问题

于 2014-04-24T12:23:27.510 回答