Okay I have this scenario here. I have a Register.aspx for registering new users. I'm using CreateUserWizard. I want the users to use only the company's email for the registration. So I placed a label beside the Email textbox showing the domain, which means the user need not to type the domain anymore. My HTML looks like this:

<asp:TextBox ID="Email" runat="server" CssClass="textEntry1"></asp:TextBox>
<asp:Label ID="lblEmail" runat="server" Text="@domain.com"></asp:Label>

So what I did to add the label to the textbox.text was as follows:

protected void RegisterUser_CreatingUser(object sender, EventArgs e)
{
    TextBox _txtEmailAddress = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Email");
    Label _lblEmailAddress = (Label)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("lblEmail");
    _txtEmailAddress.Text = _txtEmailAddress.Text + _lblEmailAddress.Text;
}

I am using the OnCreatingUser event to do this.

The _txtEmailAddress.Text would have the complete value of the email typed by the users and the domain part which I have already fixed. I was hoping to update this into the Email field so that it will be stored into the database correctly.

But as I was debugging the code, I realized that RegisterUser.Email still has the Email without the domain. Instead of getting something like "myemail@domain.com", I'm only getting "myemail" stored. Not sure if I'm going the right direction just to add my own domain to their emails. Most probably not. Any pointer would be very much appreciated.

有帮助吗?

解决方案

You need to set the .Email property of the CreateUserWizard control, not the value of the TextBox. This is what actually gets passed on the backend to the MembershipProvider's CreateUser method.

Like this:

protected void RegisterUser_CreatingUser(object sender, EventArgs e)
{
    TextBox _txtEmailAddress = (TextBox)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("Email");
    Label _lblEmailAddress = (Label)RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("lblEmail");

    // Set the email property of the CreateUserWizard control to append the domain
    RegisterUser.Email = _txtEmailAddress.Text + _lblEmailAddress.Text;
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top