What I'm trying to do: I'm creating a user through the CreateUserWizard
control and I'm trying to set the password to a randomly generated alphanumeric password. The Password TextBox
is invisible to the user(an administrator).
My attempted solution: I find the Password TextBox
and try to change the value, but the value won't set. My code is as follows:
CreateUserWizard1_CreatingUser(object sender, LoginCancelEventArgs e)
{
TextBox Password = (TextBox)CreateUserWizardStep1.ContentTemplateContainer.FindControl("Password");
Password.Text = "randomAlphaNumericPassword";
}
The Password control is found, the Text
property appears to be set, but once it leaves the event method it forgets the new value and goes back to what it originally was. I know that it's an actual reference, but can't understand why the value won't set.
Here's my asp markup:
<asp:CreateUserWizard ID="CreateUserWizard1" runat="server"
EnableViewState="False" LoginCreatedUser="False"
oncreateduser="CreateUserWizard1_CreatedUser"
oncreatinguser="CreateUserWizard1_CreatingUser"
CompleteSuccessText="A new account has been successfully created!"
ContinueDestinationPageUrl="~/Accounts.aspx"
CreateUserButtonText="Create Account"
AutoGeneratePassword="False">
<WizardSteps>
<asp:CreateUserWizardStep ID="CreateUserWizardStep1" runat="server">
<ContentTemplate>
...
<asp:TextBox ID="Password" runat="server" Visible="false"></asp:TextBox>
</ContentTemplate>
</asp:CreateUserWizardStep>
...
</WizardSteps>