Jean-Francois
Jean-Francois

Reputation: 1949

determining the type of control in Request.Form

How can you determine the type of control in Request.Form?

 foreach (string x in Request.Form.Keys)
 {                                
    if (Request.Form[x] == null || Request.Form[x].ToString() == "")
    {....

I would like to know for each loop, what is the type of control.

Is it a textbox, a listbox, a hidden field etc...

How can this be done?

Upvotes: 2

Views: 1157

Answers (2)

Tim M.
Tim M.

Reputation: 54368

Once in a great while it is useful to manually work with the Request collection rather than with strongly typed control objects. However, iterating through all controls is probably a bad idea in almost any case.

You could perform a recursive FindControl() using the keys in the Request collection. If FindControl doesn't return null, check the type of control.

Note that the key submitted is different than the actual ID of the control. It usually looks something like:

<input type="text" name="foo$bar$txtFirstName" id="foo_bar_txtFirstName" />

"name" is the actual key in the Request collection but "id" is the ID of the control. This necessitates further a further mapping step.

Upvotes: 1

usr
usr

Reputation: 171188

This is not possible. The browser does not submit this information. The HTTP standard does not contain a way to transmit this information intrinsically.

Upvotes: 0

Related Questions