daily pastebin goal
15%
SHARE
TWEET

Untitled

a guest Apr 20th, 2018 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <asp:CreateUserWizard ID="createUserWizard" runat="server"
  2.   ContinueDestinationPageUrl="/user/profile/"
  3.   CreateUserButtonText="Continue" RequireEmail="False" ActiveStepIndex="0">
  4.   <WizardSteps>
  5.    <asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server" Title="Account details">
  6.     <ContentTemplate>
  7.      <fieldset>
  8.       <legend>Account details</legend>
  9.  
  10.       <div>
  11.        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">Desired username:</asp:Label>
  12.        <asp:TextBox ID="UserName" runat="server"></asp:TextBox>
  13.       </div>
  14.       <div>
  15.        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">Desired password:</asp:Label>
  16.        <asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
  17.        <asp:RequiredFieldValidator ID="PasswordRequiredValidator" runat="server" ControlToValidate="Password"
  18.         Display="Dynamic" EnableClientScript="false" ValidationGroup="createUserWizard">*</asp:RequiredFieldValidator>
  19.       </div>
  20.       <div>
  21.        <asp:Label ID="ConfirmPasswordLabel" runat="server" AssociatedControlID="ConfirmPassword">Confirm password:</asp:Label>
  22.        <asp:TextBox runat="server" ID="ConfirmPassword" TextMode="Password"></asp:TextBox>
  23.       </div>
  24.      </fieldset>
  25.  
  26.      <div class="errors">
  27.       <asp:ValidationSummary runat="server" ID="validationSummary"
  28.        DisplayMode="BulletList" ValidationGroup="createUserWizard"
  29.        HeaderText="<b>Please correct the following fields:</b>"
  30.        ShowMessageBox="False" ShowSummary="true" />
  31.  
  32.       <asp:Literal ID="ErrorMessage" runat="server" EnableViewState="false" />
  33.      </div>
  34.     </ContentTemplate>
  35.    </asp:CreateUserWizardStep>
  36.   </WizardSteps>
  37.  </asp:CreateUserWizard>
  38.    
  39. protected override void OnInit(EventArgs e)
  40.  {
  41.   base.OnInit(e);
  42.  
  43.   createUserWizard.CreatedUser += OnUserCreated;
  44.   createUserWizard.CreateUserError += OnError;
  45.   createUserWizard.NextButtonClick += OnNextButtonClick;
  46.  }
  47.  
  48.  protected void OnUserCreated(object sender, EventArgs e)
  49.  {
  50.   //Add user to group and redirect to destination page.
  51.  }
  52.  
  53.  private void OnNextButtonClick(object sender, WizardNavigationEventArgs e)
  54.  {
  55.   CreateUserWizard wizard = sender as CreateUserWizard;
  56.  
  57.   if (wizard.ActiveStepIndex == 0)
  58.   {
  59.    try
  60.    {
  61.     if (Membership.ValidateUser(createUserWizard.UserName, createUserWizard.Password))
  62.     {
  63.      MembershipUser newUser = Membership.CreateUser(
  64.       createUserWizard.UserName,
  65.       createUserWizard.Password);
  66.  
  67.      //add user to group and redirect to destination page
  68.     }
  69.    }
  70.    catch (MembershipCreateUserException ex)
  71.    {
  72.     SetFailureMessage(ex.StatusCode);
  73.     e.Cancel = true;
  74.    }
  75.   }
  76.  }
  77.  
  78.  public void SetFailureMessage(MembershipCreateStatus status)
  79.  {
  80.   switch (status)
  81.   {
  82.    case MembershipCreateStatus.DuplicateUserName:
  83.     createUserWizard.DuplicateUserNameErrorMessage = "Username is not available."; //the string is fetched from a database.
  84.     break;
  85.  
  86.    case MembershipCreateStatus.InvalidPassword:
  87.     createUserWizard.InvalidPasswordErrorMessage = "Password is not secure enough"; //the string is fetched from a database.
  88.    ...
  89.   }
  90.  }
  91.  
  92.  private void OnError(object sender, CreateUserErrorEventArgs e)
  93.  {
  94.   if (e.CreateUserError == MembershipCreateStatus.InvalidPassword)
  95.   {
  96.    CreateUserWizard wizard = sender as CreateUserWizard;
  97.    wizard.InvalidPasswordErrorMessage = "Password is not secure enough"; //the string is fetched from a database.
  98.    ...
  99.   }
  100.  }
  101.    
  102. <asp:Label ID="lblErrorMessage" Text="" runat=server CssClass="failureNotification"></asp:Label>
  103.    
  104. try
  105. {
  106.     //Do stuff here
  107. }
  108. catch (Exception ex)
  109. {
  110.     lblErrorMessage.Text = string.Format("An error has occurred. Please tell tech support that you saw this: <br />{0}: {1}", ex.GetType(), ex.Message);
  111.     e.Cancel = true;
  112. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top