Things I'd like to have in ASP.NET
A “form element” interface so I could find out things like values from any type of form element without having to write code that’ll handle different types of form elements.
A “form element” interface so I could find out things like values from any type of form element without having to write code that’ll handle different types of form elements.
Comments
The real problem with writing cases for the different input controls is that it’ll only work for the ones that ship with ASP.NET. I couldn’t write a generic control that’d work with any other custom control that was conceptually a “form input field”. It also means that if microsoft changes any of their existing components or adds new ones I have to go and update all my components to handle the new types of form elements.
It’d simply make life easier on my current project, but it seems to me that one of the challenges with writing maintainable software is to make a system where the pieces are decoupled sufficently to contain the effects of changes as locally as possible. If my generic control needs to know about TextBoxes, DropDownLists, RadioLists and Checkboxes then it’s vulnerable to changes in any of those classes. If the FormElement interface changes (which is less likely than one of four component classes changing) then I’ve just got to update my component once and it should work with any component that implements the new interface.
Course since I don’t control the framework I’ve got to live with The Way Things Are, but I figure it’s worth complaining about the things I don’t like because if enough people do it might influence future development.
Do you mean what you get from Textbox.Text and listbox.SelectedValue?
Can’t you write a little class that can iterate through all the child controls of your form, and check the type of each one? And the determine the appropriate way to get it’s value?