gpt4 book ai didi

c# - 从 CreatedUser 事件中取消 CreateUserWizard

转载 作者:太空宇宙 更新时间:2023-11-03 11:23:04 25 4
gpt4 key购买 nike

我正在使用 CreateUserWizard 和自定义 MembershipProvider 将用户添加到我们的数据库中。目前用户已成功添加到数据库中,我正在使用 CreatedUser 事件来存储在表单上捕获的附加信息。这很好用;但是,我希望能够处理更新期间的任何错误情况。

如果附加详细信息的更新失败,有没有办法重新显示带有错误的 CreateUserWizard 表单?

这是我在 CreatedUser 事件中的代码:

protected void RegisterUserWizard_CreatedUser(object sender, EventArgs e)
{
try
{
// Try to update the customer table with the additional information
using (OrderEntities entities = new OrderEntities())
{
// Read in all the values from the form
TextBox custTitle = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerTitle");
TextBox custName = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerName");
TextBox custSurname = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerSurname");
TextBox custAddress1 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine1");
TextBox custAddress2 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine2");
TextBox custAddress3 = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerAddressLine3");
TextBox custCity = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCity");
TextBox custCounty = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCounty");
TextBox custPostcode = (TextBox)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerPostcode");
DropDownList custCountry = (DropDownList)RegisterUserWizard.CreateUserStep.ContentTemplateContainer.FindControl("CustomerCountry");

Customer custInfo = entities.Customers.Where(c => c.UserName == RegisterUserWizard.UserName).FirstOrDefault();

if (custInfo != null)
{
custInfo.Email = RegisterUserWizard.Email;
custInfo.Password = RegisterUserWizard.Password;
custInfo.Title = custTitle.Text;
custInfo.Firstname = custName.Text;
custInfo.Surname = custSurname.Text;
custInfo.AddressLine1 = custAddress1.Text;
custInfo.AddressLine2 = custAddress2.Text;
custInfo.AddressLine3 = custAddress3.Text;
custInfo.City = custCity.Text;
custInfo.County = custCounty.Text;
custInfo.Postcode = custPostcode.Text;
custInfo.CountryID = custCountry.SelectedValue;
custInfo.CreatedDate = DateTime.Now;

entities.SaveChanges();

FormsAuthentication.SetAuthCookie(RegisterUserWizard.UserName, false);

// Redirect user back to calling page
string continueUrl = RegisterUserWizard.ContinueDestinationPageUrl;
if (String.IsNullOrEmpty(continueUrl))
{
continueUrl = "~/";
}
Response.Redirect(continueUrl);

}
else
{
// Redisplay CreateUserWizard showing error message
}
}
}
catch
{
// Redisplay CreateUserWizard showing error message
}
}

提前致谢

最佳答案

如果使用内容模板添加 ID 为 ErrorMessage 的文本控件,则可以显示来自 CreateUserWizard 控件的错误。

<asp:Literal runat="server" EnableViewState="false" ID="ErrorMessage"></asp:Literal>

关于c# - 从 CreatedUser 事件中取消 CreateUserWizard,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10277812/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com