Writing code that use a "FormElement"

  • Thread starter Thread starter Helen
  • Start date Start date
H

Helen

Is there a generic way to deal with html form elements in ASP.NET? A
couple of the components I've written only really need to know that
they're dealing with an element that has a value and can do a postback
but I've had to write seperate classes (or horriblely hackish code) to
make the components work with textboxes, dropdown lists and checkboxes
because they all do things slightly differently.

I was kind of hoping there'd be a interface called FormElement that
the input and select fields implemented but the only thing these all
have in common is WebControl and that's too general for what I want.
Is there an alternative to writing three or four different versions of
my controls?

Helen
 
I would say they all implement the IPostBackDataHandler
interface ?!

But you can't access the web control's "value" or it's autopostback
attribute (which is what I neglected to say I specifically needed..
sorry) by casting to an IPostBackDataHandler?

Helen
 
the clean approach would be to subclass the html form controls you use, and
add an interface for the generic handling you want.

-- bruce (sqlwork.com)
 
You can read back the value the same way, ie by using Request.Form (or
Params if you want to support both POST and GET requests)...

Patrice

--
 
Ok didn't saw for autopostback.

Apart the other suggestion (subclassing those controls to support your own
interface), you could check for the IPostBackDataHandler and then use
Reflection to call the appropriate properties if available (perhaps a bit
more flexible if you want to support the "raw" controls (existing pages ?)
but likely less elegant from a programming point of view)...

Patrice
--
 
Back
Top