.NET的CreateUserWizard - 如何提供pre填充(和残疾人)的电子邮件字段字段、残疾人、电子邮件、NET

2023-09-06 23:56:28 作者:听风讲你

我创建一个.NET网站,这是我第一次使用CreateUserWizard控件。

I am creating a .NET website, and this is my first time using a createuserwizard control.

我需要pre-填写的电子邮件地址的用户(该网站是由仅邀请),并禁用它。但是,电子邮件领域仍需要必需的。

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.

我已成功地编辑模板,并禁用电子邮件字段,并在.aspx.cs文件编程方式填充它。然而,当我停用电子邮件字段pre-填充,下,CreateUserWizard表单不会提交。它把电子邮件字段就好像它是空的,总是返回我的创建用户页面,有红色星号的电子邮件领域。发生这种情况即使我设置RequireEmail属性设置为False。

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.

有没有办法强制用户使用指定的电子邮件地址来注册?我曾希望CreateUserWizard控件将让我的生活更轻松,但到目前为止,还没有。谢谢你。

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:

在标记,设置电子邮件为只读=true和用户名可见=假 在Page_Load中,如果里面(!回发)​​,设置电子邮件文本框为文本的电子邮件地址,并设置只读为true 在CreatingUser情况下,设置UserName.Text = Email.Text

这就是花了我 - 如果你不关心迫使用户名,我建议挂接到CreatingUser事件,检查电子邮件文本属性,以确保它的设置正确。也许别的东西清除它,你已经设置之后。

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,在我的codebehind我增加了几个特性,使其更容易地访问这些文本框,虽然有这样做的可能更好的方法:)

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);
    }