Wizard Control Question
-
I've got a
Wizard
control on my page with 21 WizardSteps. Some of the steps contain ValidationGroups. Each step that needs validation has it's own ValidationGroup defined. Now what I need to do is dynamically set theValidationGroup
property for the Next and Previous buttons in my Wizard'sStepNavigationTemplate
. For some reason, my C# code behind does not "see" the buttons in myStepNavigationTemplate
. For example, I want to code it this way:btnNext.ValidationGroup = "contactinfo";
The above does not work - a build time error occurs. I have also tried:Button btn = new Button(); btn = (Button)this.FindControl("ctl00_ContentPlaceHolder1_Wizard_StepNavigationTemplateContainerID_btnNext"); btnNext.ValidationGroup = "proofcontact";
as well as:Button btn = new Button(); btn = (Button)this.FindControl("btnNext"); btnNext.ValidationGroup = "proofcontact";
in each of the previous two above sets of code the familiar exception "Object not set to an instance..." occurs at runtime. Does anyone have a solution for this?
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.
-
I've got a
Wizard
control on my page with 21 WizardSteps. Some of the steps contain ValidationGroups. Each step that needs validation has it's own ValidationGroup defined. Now what I need to do is dynamically set theValidationGroup
property for the Next and Previous buttons in my Wizard'sStepNavigationTemplate
. For some reason, my C# code behind does not "see" the buttons in myStepNavigationTemplate
. For example, I want to code it this way:btnNext.ValidationGroup = "contactinfo";
The above does not work - a build time error occurs. I have also tried:Button btn = new Button(); btn = (Button)this.FindControl("ctl00_ContentPlaceHolder1_Wizard_StepNavigationTemplateContainerID_btnNext"); btnNext.ValidationGroup = "proofcontact";
as well as:Button btn = new Button(); btn = (Button)this.FindControl("btnNext"); btnNext.ValidationGroup = "proofcontact";
in each of the previous two above sets of code the familiar exception "Object not set to an instance..." occurs at runtime. Does anyone have a solution for this?
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.
Ok, I found a solution though it's prbably not the best. I brute forced it into seaching the whole form for the correct control with this function:
private Control FindIt(Control inCtrl, String ctrlEnd) { foreach (Control Ctrl in inCtrl.Controls) { if (Ctrl.ID == ctrlEnd) { return Ctrl; } else { if (Ctrl.HasControls()) { Control c = null; c = FindIt(Ctrl,ctrlEnd); if (!(c == null)) { return c; } } } } return null; }
So I call it like this in the next button click event:if (Wizard.ActiveStepIndex == 16) { Button btn = new Button(); btn = (Button)FindMyControl(this, "btnNext"); if (!(btn == null)) { btn.ValidationGroup = "proofcontact"; } }
"Half this game is ninety percent mental." - Yogi Berra If you can read thank a teacher, if you can read in English, thank a Marine.