0

I've noticed that, during a postback, Request.Form[MyControl.ClientID] is null. However, Request.Form[MyControl.Name] contains the expected value.

This is unexpected. Is this documented somewhere?

leppie
  • 115,091
  • 17
  • 196
  • 297
Jonathan Wood
  • 65,341
  • 71
  • 269
  • 466

1 Answers1

7

This is correct - browser will use control's name (and not ID) for posting the values. Further, use Request.Form[MyControl.UniqueID] to get the value from POST data (because ASP.NET uses that value as control name in the generated html while ClientID is used as html id).

See W3C documentation that describes the form submission - check 17.13.2 & 17.13.3.

VinayC
  • 47,395
  • 5
  • 59
  • 72
  • Thanks for the info. I'm not sure I understand `MyControl.UniqueID`. It contains the exact same value as `MyControl.Name`. – Jonathan Wood Jul 01 '11 at 05:23
  • @Jonathan, I am not sure which control type you are using here but not every ASP.NET control will have `Name` property but `UniqueID` will be present in each one (as it is present on the base `Control` class). – VinayC Jul 01 '11 at 05:28
  • I see. I'm working with the DropDown control, which has both properties, and both properties contain the same value. Thanks for the link, although it seems related to web pages in general, and not properties of ASP.NET controls. – Jonathan Wood Jul 01 '11 at 07:24
  • 1
    @Jonathan, W3C standards mandate browsers to send html control values against names (and not id) - its applicable for html/user-agents irrespective of technology. ASP.NET server controls uses `ID` property for server side identifier, `ClientID` property for html id and `UniqueID` property for html name. – VinayC Jul 01 '11 at 08:26