CreateUserWizard更改运行时错误消息
第一次使用 ASP.NET CreateUserWizard 控件,我们将用户名文本框别名为电子邮件地址,因为客户希望用户名是电子邮件地址。然后隐藏该控件 EmailAddress。这部分工作正常。我遇到的问题是用户界面上显示的错误消息显示“请输入不同的用户名”。如果您输入现有的电子邮件地址。我们需要将其更改为“请输入不同的电子邮件地址”。我为 OnCreateUserError 添加了一个事件处理程序。添加了下面的代码,并调试事件并设置要显示的错误消息的 Literal.Text。仍然会在以后的事件中被覆盖。有谁知道我缺少什么才能将此错误消息发送到用户界面。
protected void userWizard_CreateUserError(object sender, CreateUserErrorEventArgs e)
{
// check for dupe username error
if (e.CreateUserError == MembershipCreateStatus.DuplicateUserName)
{
// If so change to dupe email error and set the literal
e.CreateUserError = MembershipCreateStatus.DuplicateEmail;
Literal errorMessage = (Literal)userWizard.WizardSteps[0].Controls[0].Controls[0].Controls[0].Controls[0].FindControl("ErrorMessage");
errorMessage.Text = "Email address already exists. Please enter a different email address.";
}
}
First time using the ASP.NET CreateUserWizard control and we are aliasing the Username Textbox as the Email Address because the clients wants the username to be an email address. Then hiding that controls EmailAddress. This part is working fine. The problem I'm having is the error message that gets displayed on the UI says "Please enter a different user name." if you type in a existing email address. We need to change this to "Please enter a different email address". I added a event handler for the OnCreateUserError. Added the code below, and debugging the events gets hit and sets the Literal.Text of the error message to display. Still gets overwritten on a later event. Does anyone know what I'm missing to get this error message to the UI.
protected void userWizard_CreateUserError(object sender, CreateUserErrorEventArgs e)
{
// check for dupe username error
if (e.CreateUserError == MembershipCreateStatus.DuplicateUserName)
{
// If so change to dupe email error and set the literal
e.CreateUserError = MembershipCreateStatus.DuplicateEmail;
Literal errorMessage = (Literal)userWizard.WizardSteps[0].Controls[0].Controls[0].Controls[0].Controls[0].FindControl("ErrorMessage");
errorMessage.Text = "Email address already exists. Please enter a different email address.";
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试设置 CreateUserWizard 的 DuplicateUserNameErrorMessage 属性 相反。
Try setting the CreateUserWizard's DuplicateUserNameErrorMessage Property instead.