.NET createuserwizard - how to provide a pre-filled (and disabled) email field
I am creating a .NET website, and this is my first time using a createuserwizard control.
I need to pre-fill the email address for users (the website is by invitation only) and disable it. However, the email field still needs to be required.
I have managed to edit the template and disable the email field, and fill it programatically in the .aspx.cs file. However, when I disable the email field and pre-fill it, the createuserwizard form will not submit. It treats the email field as if it were empty and always returns me to the create开发者_开发技巧 user page, with a red asterisk by the email field. This happens even if I set the RequireEmail property to False.
Is there a way to force users to register with a given email address? I had hoped the createuserwizard would make my life easier, but so far it hasn't. Thanks.
I've done something like this - in my case I didn't want a separate username, I used their email address as their username (and didn't allow them to change it), so I did:
- in the markup, set Email to ReadOnly="true" and UserName to Visible="false"
- in Page_Load, inside if (!postback), set the Email textbox to Text to the email address and set ReadOnly to true
- in the CreatingUser event, set UserName.Text = Email.Text
That's all it took for me - if you don't care about forcing the username, I'd recommend hooking up to the CreatingUser event and inspect the email Text property to make sure it's set properly. Perhaps something else is clearing it after you've set it.
FWIW, in my codebehind I added a couple of properties to make it easier to access those textboxes, although there's likely better ways of doing this :)
private TextBox UserName {
get { return GetWizardControl<TextBox>("UserName"); }
}
private TextBox Email {
get { return GetWizardControl<TextBox>("Email"); }
}
private T GetWizardControl<T>(string id) where T : Control {
return (T)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl(id);
}
An alternative solution was to set the Disabled property on the required field validator for Email -- I did this manually by editing the aspx code. I didn't fully test this alternative, since the answer provided by James Manning worked for me.
READONLY and DISABLED both remove the functionality of the input field, but to different degrees. READONLY locks the field: the user cannot change the value. DISABLED does the same thing but takes it further: the user cannot use the field in any way, not to highlight the text for copying, not to select the checkbox, not to submit the form. In fact, a disabled field is not even sent if the form is submitted.
Taken from here: http://www.htmlcodetutorial.com/forms/_INPUT_DISABLED.html
精彩评论