Saturday, March 24, 2012

Wizard Control with Validation in UpdatePanel

Hi, I met a problem that I don't know how to solve when using a Wizard control with Validation in updatePanel. I am using ASP.NET 2.0 and ASP.NET 2.0 AJAX Extension 1.0. Below is the sample code and the problem I had is that after I went to Step 2 if I click Previous Button to go back to Step 1, the validator is not showing its validation result. Did I do anything wrong in my code? Would appreciate if anyone could help! Also, got a side question that how do I preserve the value in a password TextBox if I am going from Step 2 to Step 1, i.e. if the TextBox1's TextMode is set to Password, is there anyway to preserve its value?

<

formid="form1"runat="server">
<asp:ScriptManagerID="ScriptMan"runat="server" />
<asp:UpdatePanelID="UpdatePanel1"runat="server">
<ContentTemplate>
<asp:WizardID="Wizard1"runat="server"DisplaySideBar="false">
<WizardSteps>
<asp:TemplatedWizardStepID="TemplatedWizardStep1"runat="server"StepType="Start"Title="step 1">
<ContentTemplate>
Step 1<br/>
ASDF:
<asp:TextBoxID="TextBox1"runat="server"></asp:TextBox>
<asp:RequiredFieldValidatorID="RequiredFieldValidator1"runat="server"ControlToValidate="TextBox1"ValidationGroup="asdf"ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
</ContentTemplate>
<CustomNavigationTemplate>
<asp:ButtonID="StepNextButton"runat="server"CommandName="MoveNext"Text="Next"CausesValidation="true"ValidationGroup="asdf"/>
</CustomNavigationTemplate>
</asp:TemplatedWizardStep>
<asp:TemplatedWizardStepID="TemplatedWizardStep2"runat="server"StepType="Finish"Title="step 2">
<ContentTemplate>
Step 2
</ContentTemplate>
<CustomNavigationTemplate>
<asp:ButtonID="FinishPreviousButton"runat="server"CausesValidation="False"CommandName="MovePrevious"Text="Previous"/>
<asp:ButtonID="FinishButton"runat="server"CommandName="MoveComplete"Text="Finish"/>
</CustomNavigationTemplate>
</asp:TemplatedWizardStep>
<asp:TemplatedWizardStepID="TemplatedWizardStep3"runat="server"StepType="Complete"Title="Complete">
<ContentTemplate>
Complete
</ContentTemplate>
<CustomNavigationTemplate>
<asp:ButtonID="ContinueButton"runat="server"CausesValidation="False"CommandName="Continue"Text="Continue"/>
</CustomNavigationTemplate>
</asp:TemplatedWizardStep>
</WizardSteps>
</asp:Wizard>
</ContentTemplate>
</asp:UpdatePanel>
</form>Hi, my bad that I did not do enough researching before this posting, the problem has been resolved after I fonudthis blog entry of Matt Gibbs. It turns out that it is a known issue perhttp://ajax.asp.net/docs/overview/UpdatePanelOverview.aspx, and the workaround is to disable ClientScript of the validator controls. However, if you don't like the round trip traffic, Matt has posted Ajax Validators. I was not aware of this since I did not join the beta/CTP of the ASP.NET AJAX.

Validators are not compatablw with ASP.NET AJAX Final version..

Check this link

http://weblogs.asp.net/scottgu/archive/2007/01/25/links-to-asp-net-ajax-1-0-resources-and-answers-to-some-common-questions.aspx

You can download the stable version of Validators from here

http://blogs.msdn.com/mattgi/archive/2007/01/23/asp-net-ajax-validators.aspx


Johnny, I am curious if you ever found a solution to your other problem about losing the password value going from step 1 to step 2. I am currently facingt the same issue and I have found no answers.

I am casting the password box in the following way:

// make reference to the password step
TemplatedWizardStep passwordStep = SelectPasswordStep;

// password step
TextBox PasswordChoice =
(TextBox)passwordStep.ContentTemplateContainer.FindControl("Password");

Response.Write(PasswordChoice.Text);

When I have the Password control set as textmode=password the text value returns blank. No error, just an empty value. When I have the textmode as singleline it works. Something about a textmode of password seems to make the control lose its value. Anybody have any ideas. Is this a bug or by design for some Redmond reason?

- jq



Chetan, thanks for you replay.

Jq, I was not working the "side problem" right now, however, I think you can preserve the actuall password string when going from step 1 to step 2, and when you go back to step 1, u could assign the password back to textbox. I guess it's not a bug and should be deisgned to be that way for security reason. I hope the work around could work, if you are going try this out, please let me know the result. Thanks.


I actually wasn't even able to get to this point. My problem is that I can't do ANYTHING with the password textbox control. Moving to the next step, referencing the control via code-behind, or anything -- once I have moved past the step with the password control, I lose the value.

So when I'm at the end of the wizard and I'm creating my account, I have lost my password value. So I can't even create the account, making my entire wizard useless. With your solution, can you read the value of the password field? If so would you mind posting your code?

Thanks,

JQ

No comments:

Post a Comment