我使用CreateUserWizard的自定义创建用户步骤,然后在安全答案下边加了一行,然后放进去一个label和一个DropDownList 。为什么我在CreateUserWizard的CreatedUser事件里无法访问到这个控件。。CreateUserWizard控件自身包含控件的都可以用CreateUserWizard.*的方式来访问。直接在事件里写控件名称同样找不到新加的控件。。哪位达人指教一下。。谢谢。

解决方案 »

  1.   

    以下代码初中Msdn:ms-help://MS.MSDNQTR.v90.chs/dv_vwdcon/html/7983d61e-d317-4181-8ab9-cab549adf9dc.htm<%@ Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
      protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
      {
        // Determine the checkbox values.
        CheckBox subscribeCheckBox = 
          (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("SubscribeCheckBox");
        CheckBox shareInfoCheckBox =
          (CheckBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("ShareInfoCheckBox");
        TextBox userNameTextBox = 
          (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("UserName");    MembershipUser user = Membership.GetUser(userNameTextBox.Text);
        user.Comment = "Subscribe=" + subscribeCheckBox.Checked.ToString() + "&" +
                       "ShareInfo=" + shareInfoCheckBox.Checked.ToString();
        Membership.UpdateUser(user);    // Show or hide the labels based on the checkbox values.
        Label subscribeLabel = 
          (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("SubscribeLabel");
        Label shareInfoLabel =
          (Label)CreateUserWizard1.CompleteStep.ContentTemplateContainer.FindControl("ShareInfoLabel");    subscribeLabel.Visible = subscribeCheckBox.Checked;
        shareInfoLabel.Visible = shareInfoCheckBox.Checked;
      }  private bool UserExists(string username)
      {
          if (Membership.GetUser(username) != null) { return true; }      return false;
      }  protected void CreateUserWizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
      {
          if (e.CurrentStepIndex == 0)
          {
              if (SearchAccount.Text.Trim() == "" || UserExists(SearchAccount.Text))
              {
                  SearchAccountMessage.Text = "That account already exists. Please select an different account name.";
                  e.Cancel = true;
              }
              else
              {
                  TextBox userName =
                    (TextBox)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("UserName");
                  userName.Text = SearchAccount.Text;
                  SearchAccountMessage.Text = "";
                  e.Cancel = false;
              }
          }
      }
    </script>
      

  2.   

    呵呵,果然可以,问题解决!多谢liuyeede 的帮助!