开发者

Can't clear credentials textboxes on ASP.NET CreateUserWizard Control

I have a CreateUserWizard control using forms authentication on my login/create user page. I customized the CreateUserWizardStep1 so that I could add some additional validators.

After successfully creating a user with the control and it displays "Complete Your account has been successfully created." I have added an additional button that will allow the person to create another user by setting the ActiveStepIndex = 0. The problem is, while it sets the ActiveStepIndex correctly, it retains the old user account credentials. I try to clear them manually using the following code, but they still stick...Anyone have any ideas?

   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

It finds the textboxes correctly, but it does not actually reset their values, even though in the debugger it says it did.

Thoughts ?


What happens if you call Response.Redirect(Request.Url.ToString(), true)? That should clear everything for you.

Also, the recursive nature of the FindControlIterative call would make your code quite expensive to run as it has to drill down into the control heirarchy for every control that you are looking for.

The problem with your code is that: In a Wizard control, ViewState is not responsible for storing the modified values for controls such as TextBoxes. These controls implement the IPostBackDataHandler interface. The LoadPostBackData event fires in the page lifecycle, in which the VALUES of the controls load from the form HTTP POST headers... which are resubmitted by the client...

So how to destroy the HTTP POST Headers to clear the control values?

A new request results in new HTTP POST Headers... simply do this in the Button click event handler:

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

This has the added benefit that it goes to Step 1 of the wizard so you also dont have to do... wiz.MoveTo(wiz.WizardSteps[0]).

Credit to Konrad - ASP.Net Wizard - How to clear contents of web controls


I feel silly posting this..., but I just turned viewstate off on the CreateUserWizard control and that did it.

Thanks for the help Daniel, I now have a better understanding on how ASP.NET stores information.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜