How to Pass a Page to a function in the code behind

Kane Jeeves

Active member
Joined
May 17, 2006
Messages
44
Programming Experience
5-10
I have several aspx pages that display the same 75+ fields (but each page has different functionality). I also have an object "MyRequest" to contain the field values so that I can do various other things including saving to tables.

Instead of repeating the code to load MyRequest from the page on each form, I'd like to pass the page itself (or control collection?) as an object to a central routine that does the loading.

I'm pretty sure you can do this, but I'm guessing I'd have to then use FindControl for every field, which seems like it'd be very slow on 75+ fields.

Is there a way to do what I want and still refer to fields like you normally do in the code behind, eg: MyRequest.SomeField = SomeTextbox.Text (where SomeTextbox is a field on the page).

Thoughts?

TIA,
Kane
 
Use reflection to assign values in your controls. You name your controls most likely the same as your database fields so that you have a way to determine which field will be map for each control.
 
Back
Top