control id and name for postback mechanism - 08-18-2006 , 03:26 AM
This may be a dumb question, but why is it necessary for a control's id and
name attribute to coincide in order for the postback mechanism to work?
Given that it appears to be necessary, why are they not wired to be the same
value in a base class like control or webcontrol?
Re: control id and name for postback mechanism - 08-20-2006 , 03:55 AM
Remember that the value in name attribute matches control's UniqueID, that
is unique ID value so that control can be distinguished from the other
controls, e.g to know which control is in question. UniqueID contains path
of IDs with predefined separators revealing the control path in which the
current control is located in.
Page.FindControl method on the other hand is able to locate the control (and
return reference to it) when it is given a unique id. In other words it
doesn't need to loop through all the controls, evaluating which one's ID
would match. And this is used with postback processing, and is one reason
why name must match UniqueID. It not just finds the control, superfast, but
also causes child control hierarchies to be created (ensures that control
receiving postback is there).
ASP.NET MVP, AspInsider
"Martin" <firstname.lastname@example.org> wrote
|Thread Tools||Search this Thread|