Avatar of VGMForbin
VGMForbin
 asked on

Adding attributes to controls in a Wizard control

I have a Wizard control with several steps.  On the first step I have two RadioButtonList controls (they both contain two items: Yes and No).  If the user selects yes (index 0) the corresponding row will be come unhidden.  If they select no (index 1) the corresponding row will become hidden.  You can see the code below that I am running in my Form.Load method.  This is tested and working correctly.

I am trying to add the same functionality for a third RadioButtonList on another step further in the Wizard.  I cannot make this work using the same method, and I'm assuming it's because that RadioButtonList doesn't exist on my Form.Load because it's on a future step.

Can anybody tell what I am doing wrong, and what is the prefered way of doing this?
FirstRadioButtonList.Items[0].Attributes.Add("onclick", "javascript:displayElement('FirstRow', true)");
FirstRadioButtonList.Items[1].Attributes.Add("onclick", "javascript:displayElement('FirstRow', false)");
 
SecRadioButtonList.Items[0].Attributes.Add("onclick", "javascript:displayElement('SecRow', true)");
SecRadioButtonList.Items[1].Attributes.Add("onclick", "javascript:displayElement('SecRow', false)");
 
ThirdRadioButtonList.Items[0].Attributes.Add("onclick", "javascript:displayElement('ThirdRow', true)");
ThirdRadioButtonList.Items[1].Attributes.Add("onclick", "javascript:displayElement('ThirdRow', false)");

Open in new window

.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
VGMForbin

8/22/2022 - Mon
aibusinesssolutions

Put the code in the Wizard1_ActiveStepChanged, and since the user could be on any step, first run a check to see if it exists.
ASKER CERTIFIED SOLUTION
aibusinesssolutions

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
aibusinesssolutions

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
VGMForbin

ASKER
I'm assuming this code would then need to run on Form.Load whether it was a postback or not?
SOLUTION
aibusinesssolutions

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
VGMForbin

ASKER
Yes, that approach works.

However, on one of my wizard steps I have functionality that includes a postback, and my attribute seems to be lost after postback.  This would indicate that I would need to include this in the Form.Load instead of in the ActiveStepChanged event, correct?
Your help has saved me hundreds of hours of internet surfing.
fblack61
aibusinesssolutions

Well, it depends on what it is doing, but yes, it would be simpler to just put it in the form_load, outside of the "if not ispostback".
VGMForbin

ASKER
That's where I have it now, however, it appears Wizard1.ActiveStepIndex is equal to the index before the post, not after.
aibusinesssolutions

Ok, instead of using ActiveStepIndex, just check to see if the control exists.

Something like

if (ThirdRadioButtonList != null) {
ThirdRadioButtonList.Items[0].Attributes.Add("onclick", "javascript:displayElement('ThirdRow', true)");
ThirdRadioButtonList.Items[1].Attributes.Add("onclick", "javascript:displayElement('ThirdRow', false)");
}

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
VGMForbin

ASKER
I have placed the switch statement in the PreRender event of the Wizard and this seems to work as I want it to.  I think your latest solution would work as well, but I think I may keep it in the PreRender unless you have a good reason not to.

Thanks for your help!  I learned a lot.
aibusinesssolutions

It will work in PreRender as well, that's the thing about asp.net, there's always at least 10 ways do do the same thing. :)
VGMForbin

ASKER
That's for sure.  Thanks again for the help!
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes