Reflecting through a form to find controls

R

Robert Bravery

Hi All,

I have an asp page with a wizard. On each page of the wizard I have
different user controls with objects on for user input. Like textboxes,
radiobuttonlist etc
I have also set up a controler class, which has the job of loading and
saving data from the form to a model

In order to get the control values I used this method
TextBox CompanyName = cntrl.FindControl("CompanyName") as TextBox
then I load the value into my model like so
cntrl.comp.IndividualShareholderCollection[ind].CompanyName

This works fine for a few controls on the form
But when there are large amounts of data to input, I don't want to go
through this manual process.
SO I thought of using reflection. I can reflect throu my model class an get
its properties and values and set its values.
But I am haing difficulty on how I can reflect through the usercontrol on
the wizard to get the controls and its values

Any help in pointing me in the right direction is appreciated

Thanks
Robert
 
P

Phil Johnson

Reflection would be costly and I'm not sure it is what you want... can you
not just use the pages control collection?

http://technet.microsoft.com/en-us/library/20zys56y(VS.80).aspx

If you have a lot of controls inside controls etc you could create a
recursive function that look at all the controls in the page collection, then
passes each control back into itself and looks at the all the controls in the
controls collection etc.

--
Regards,

Phillip Johnson (MCSD For .NET)
PJ Software Development
www.pjsoftwaredevelopment.com
 

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

Top