views:

19

answers:

2

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 ?

+1  A: 

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 - http://stackoverflow.com/questions/833281/asp-net-wizard-how-to-clear-contents-of-web-controls

Daniel Dyson
That works, but it also nukes a hiddenfield that I use as a flag to decide wether or not to display a "You must agree to.." privacy policy JavaScript popup. What is wrong with my original code?
bulltorious
See my edited answer about hpw the values are set. You might have to store that hidden field value and pass it back to the page, either in SessionState or in the URL, if not sensitive.
Daniel Dyson
A: 

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.

bulltorious