Wizard Control - Referencing buttons in <StepNavigationTemplate>

B

beaudetious

I've got a wizard control setup where I use the NavigationTemplates to
control the navigation buttons. My setup (very generally and with no
specifics) looks like this:

<asp:Wizard>
<StartNavigationTemplate></StartNavigationTemplate>
<StepNavigationTemplate></StepNavigationTemplate>
<FinishNavigationTemplate></FinishNavigationTemplate>
<WizardSteps>
<asp:WizardStep ID="WizardStep1" runat="server" stepType="start">
</asp:WizardStep>
<asp:WizardStep ID="WizardStep2" runat="server" stepType="step">
</asp:WizardStep>
<asp:WizardStep ID="WizardStep3" runat="server" stepType="finish">
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>

Of course, I've got controls inside the tags where they belong and the
Wizard is working wonderfully except validation is a bit flaky. My problem
is that I have to change some properties on the buttons inside the
<StepNavigationTemplate> section depending on which <WizardStep> I'm in.

The documentation says to use the wizard's FindControl method but that
method doesn't work (I keep getting null). I tried looping through the
wizard's control collection but that only contains a single control and it's
not my button. The <StepNavigationTemplate> doesn't seem to be available
from the WizardSteps items either.

This seems like a very normal thing to do. So what gives?

Brian
 
J

jeffrey.leach

Brian,

I'm running into the same problem. Did you ever find out how to
reference controls inside the stepNavigationTemplate?

-Jeff
 
B

beaudetious

I never did get any answer on this either from this newsgroup or the ASP.NET
forums. I ended up combining one of my steps with another for a total of 3
steps (start, step and finish). Doing it that way allowed me to have control
of the button's behaviour in each step Template. Good luck.

Brian
 
B

Brock Allen

TextBox tb1 = WizardStep1.CustomNavigationTemplateContainer.FindControl("TextBox1")
as TextBox;
 
J

jeffrey.leach

Thanks Brock!

Can you only access the buttons in a customTemplatedStep?
I would really prefer to access the navigation buttons on a wizard
step. Often times I just want to change the name of a navigational
button on one step or associate some javascript with the button.
Is there a way to do this?
As soon as I use a customTemplatedStep I have to write twice as much
code to find all the controls on the associated
ContentTemplateContanier.
Me.myTemplatedStep.ContentTemplateContainer.FindControl("SomeControl")

Is there a way to access the wizardstep navigation buttons? If not is
there a way to avoid having to use findControl to find all of the
controls in the content template?

Thanks,
Jeff
 
J

jeffrey.leach

Thanks Brock!

Can you only access the buttons in a customTemplatedStep?
I would really prefer to access the navigation buttons on a wizard
step. Often times I just want to change the name of a navigational
button on one step or associate some javascript with the button.

As soon as I use a customTemplatedStep I have to write twice as much
code to find all the controls on the associated
ContentTemplateContanier.
Me.myTemplatedStep.ContentTemplateContainer.FindControl("SomeControl")

Is there a way to access the wizardstep navigation buttons? If not is
there a way to avoid having to use findControl to find all of the
controls in the content template?

Thanks,
Jeff
 
J

James

I don't know if you figured this out or not, but I think I may have a
way to help. I ran into the same exact problem. I was really excited
about using the new wizard control and built a really complex wizard. I
thought, "hey, i'll work on the validation when I'm done with the
wizard." Ooops.

Here are the steps (and I'll provide some code later):
1. Cause the "OnNextButtonClick" event to call a function (declare that
in the asp:Wizard control)
<asp:Wizard ID="wizSignup" runat="server"
OnNextButtonClick="wizSignup_NextButtonClick">
2. Create a wizard step (in my example I use "wizstepContact")
2.a. Create as many wizard steps as you want. use meaningful IDs as you
will use these IDs to find out what step the wizard is on (and then
determine which validation group to call).
3. Create a function using the name you used for "OnNextButtonClick"
(be sure to use the WizardNavigationEventArgs type for the event arg
paramter).

Here's my code:
protected void wizSignup_NextButtonClick(object sender,
WizardNavigationEventArgs e)
{
//see if the "ActiveStep" matches "wizstepContact"
if (this.wizSignup.ActiveStep == this.wizstepContact)
{
//Validate the validation group that corresponds to this wizard step
this.Page.Validate("valgroupContactInformation");
if (!this.Page.IsValid)
{
//if it's not valid, stop the wizard from going to the next step by
using
// WizardNavigationEventArgs e.Cancel = true;
e.Cancel = true;
}
}
//see if the "ActiveStep" matches "wizstepPaymentInformation"
else if (wizSignup.ActiveStep ==
this.wizstepPaymentInformation)
{
//Validate the validation group that corresponds to this wizard step
this.Page.Validate("valgroupPaymentInformation");
if (!Page.IsValid)
{
//if it's not valid, stop the wizard from going to the next step by
using
// WizardNavigationEventArgs e.Cancel = true;
e.Cancel = true;
}
}
}

I did not use Step, Start, or Finish templates, although you can since
the OnNextButtonClick event fires. If you're using the side navigation,
you may need to handle that click event as well. If you want to
validation on the FinishClick then include that in you asp:Wizard
declaration as well.

Hopefully this helps. I couldn't find this anywhere on the net. Mostly,
people avoided talking about validation in all of the hype...probably
because they didn't want to mention that it is a pain.

Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top