asp.net - 无法清除 ASP.NET CreateUserWizard 控件上的凭据文本框

标签 asp.net findcontrol createuserwizard

我在登录/创建用户页面上有一个使用表单例份验证的 CreateUserWizard 控件。我自定义了 CreateUserWizardStep1 以便我可以添加一些额外的验证器。

使用控件成功创建用户后,显示“完成
您的帐户已成功创建。”我添加了一个附加按钮,允许该人通过设置 ActiveStepIndex = 0 创建另一个用户。问题是,虽然它正确设置了 ActiveStepIndex,但它保留了旧的用户帐户凭据。我尝试使用以下代码手动清除它们,但它们仍然坚持......有人有什么想法吗?

   Protected Sub btnCreateAnotherUser_Click(ByVal sender As Object, ByVal e As System.EventArgs)

    Me.cuwMain.ActiveStepIndex = 0
    CleanCreateNewUserInput()

End Sub

Private Sub CleanCreateNewUserInput()

    Dim txtUserName As TextBox
    txtUserName = FindControlIterative(Me.cuwMain, "UserName")
    txtUserName.Text = String.Empty

    Dim txtPassword As TextBox
    txtPassword = FindControlIterative(Me.cuwMain, "Password")
    txtPassword.Text = String.Empty

    Dim txtConfirmPassword As TextBox
    txtConfirmPassword = FindControlIterative(Me.cuwMain, "ConfirmPassword")
    txtConfirmPassword.Text = String.Empty

    Dim txtEmail As TextBox
    txtEmail = FindControlIterative(Me.cuwMain, "Email")
    txtEmail.Text = String.Empty

    Dim txtQuestion As TextBox
    txtQuestion = FindControlIterative(Me.cuwMain, "Question")
    txtQuestion.Text = String.Empty

    Dim txtAnswer As TextBox
    txtAnswer = FindControlIterative(Me.cuwMain, "Answer")
    txtAnswer.Text = String.Empty

End Sub

它正确地找到了文本框,但实际上并没有重置它们的值,即使在调试器中它说它确实如此。

想法?

最佳答案

如果您调用 Response.Redirect(Request.Url.ToString(), true) 会发生什么? ?那应该为您清除一切。

此外,FindControlIterative 调用的递归性质会使您的代码运行起来非常昂贵,因为它必须深入了解您要查找的每个控件的控件层次结构。

您的代码的问题在于:
在 Wizard 控件中,ViewState 不负责为控件(例如 TextBoxes)存储修改后的值。这些控件实现 IPostBackDataHandler 接口(interface)。 LoadPostBackData 事件在页面生命周期中触发,其中控件的 VALUES 从表单 HTTP POST header 加载...由客户端重新提交...

那么如何销毁 HTTP POST Headers 来清除控制值呢?

一个新的请求会产生新的 HTTP POST header ...只需在按钮单击事件处理程序中执行此操作:

Response.Redirect(Page.Request.Url.ToString());

这有一个额外的好处,它可以进入向导的第 1 步,因此您也不必这样做... wiz.MoveTo(wiz.WizardSteps[0])。

归功于康拉德 - ASP.Net Wizard - How to clear contents of web controls

关于asp.net - 无法清除 ASP.NET CreateUserWizard 控件上的凭据文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3101892/

相关文章:

asp.net - 表不工作

asp.net - 如何获取位于表单 View 的 insertitemtemplate 内的下拉列表用户控件的选定值?

asp.net - 分机号 :simple ComboBox binding issue

c# - 用户单击行链接按钮控件时如何获取中继器的项目行ID

c# - 如何在GridView的TemplateField中找到Control?

asp.net - CreateUserWizard - 添加步骤但在所有步骤完成之前不要创建用户

c# - 从 CreatedUser 事件中取消 CreateUserWizard

java - 我如何使用java创建Facebook帐户

c# - 如何使用 C# 从 ASP.NET 检索 MAC id

asp.net - 配置asp.net web.config session