control id and name for postback mechanism

M

Martin

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
 
T

Teemu Keiski

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,268
Messages
2,571,095
Members
48,773
Latest member
Kaybee

Latest Threads

Top