all groups > asp.net building controls > august 2006 >
You're in the

asp.net building controls

group:

control id and name for postback mechanism


control id and name for postback mechanism Martin
8/18/2006 12:00:00 AM
asp.net building controls:
Hi,

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?

Thanks
Martin

Re: control id and name for postback mechanism Teemu Keiski
8/20/2006 12:00:00 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).

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

[quoted text, click to view]

AddThis Social Bookmark Button