在 ASP.NET Webforms 中,ChangePassword:如何将 SuccessTemplate 设置为在更改密码后可见?

发布于 2024-08-04 03:06:48 字数 924 浏览 10 评论 0原文

它确实允许我更改密码,但视图将重置为原始状态。

OnInit 看起来像这样:

changePassword.ChangingPassword += ChangePasswordButton_Click;

方法实现:

private void ChangePasswordButton_Click(object sender, EventArgs args)
{
 MembershipUser user = Membership.GetUser();

 string oldPassword = changePassword.CurrentPassword;
 string newPassword = changePassword.NewPassword;

 try
 {
  if (user.ChangePassword(oldPassword, newPassword))
  {
   //TODO: set successtemplate to visible. How? Who knows.
   //Response.Write("Changes were successful");
  }
  else
  {
   //Response.Write("Failed to change password");
  }
 }
 catch (ArgumentException e)
 {
  //Response.Write("Password could not be changed due to: " + e.Message);
 }
}

我确实可以在应该更改密码时更改密码,因此它确实会获取成员资格提供程序配置。

我在 aspx 文件中同时有 SuccessTemplate 和 ChangePasswordTemplate,但我不知道如何使 ChangePassword 控件显示 SuccessTemplate。我缺少什么?

It does allow me to change the password but the view is reset to its original state.

OnInit looks like this:

changePassword.ChangingPassword += ChangePasswordButton_Click;

and the method implementation:

private void ChangePasswordButton_Click(object sender, EventArgs args)
{
 MembershipUser user = Membership.GetUser();

 string oldPassword = changePassword.CurrentPassword;
 string newPassword = changePassword.NewPassword;

 try
 {
  if (user.ChangePassword(oldPassword, newPassword))
  {
   //TODO: set successtemplate to visible. How? Who knows.
   //Response.Write("Changes were successful");
  }
  else
  {
   //Response.Write("Failed to change password");
  }
 }
 catch (ArgumentException e)
 {
  //Response.Write("Password could not be changed due to: " + e.Message);
 }
}

I do get to change the password when I'm supposed to, so it does pickup the membership provider configuration.

I have both a SuccessTemplate and a ChangePasswordTemplate in the aspx file but I don't know how to make the ChangePassword control display the SuccessTemplate. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

尐偏执 2024-08-11 03:06:48

(通过问题编辑回答。转换为社区 wiki 答案。请参阅 问题没有答案,但问题在评论中解决(或在聊天中扩展)

OP 写道:

已解决:

changePassword.SuccessTemplate.InstantiateIn(changePassword);
changePassword.ChangePasswordTemplateContainer.Visible = false;

(Answered by a question edit. Converted to a community wiki answer. See Question with no answers, but issue solved in the comments (or extended in chat) )

The OP wrote:

Solved:

changePassword.SuccessTemplate.InstantiateIn(changePassword);
changePassword.ChangePasswordTemplateContainer.Visible = false;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文