Let me present some notes concerning section Creating a Complete Custom Control/Adding Constituent Controls
of Chapter 3. I think there are some minor misprints and omissions which can confuse unaware reader. Sorry if I am wrong.
Second paragraph on page 77 states:
quote:Another way to ensure that your constituent controls have unique names is to not set the Id property for
your constituent controls. If you don’t set the Id property then unique values are automatically generated
for the name and id attributes of your constituent controls when your custom control is added to the page.
However, these values are essentially random values, affected by what other controls on the page are also
assigned automatic identifiers.
But if you don’t set Id property for constituent control its id attribute will not be rendered as opposed to name attribute and will not be available for client side code.
Another paragraph on page 77:
quote:You can retrieve the unique identifier that’s assigned to a control after the control has been added to the
Controls collection. You can then use that identifier when generating client-side code. This Visual Basic
2005 code retrieves the unique client-side identifier for a control:
And further there is an example of retrieving UniqueID property.
First: it is ClientID property that can be used for client-side code not UniqueID (though internally UniqueID is used to get ClientID but format still differs). There is another sentence on page 76 that in my opinion indirectly erroneously states that id attribute for HTML control will be taken from UniqueID property:
quote:At run time, when the HTML for your control is generated, the unique identifier for your control’s
client-side HTML is retrieved by reading your control’s UniqueId property.
Second – code example in VB
and C# shows that instance of button is created and a variable is set to this button’s UniqueID property value. But control is not added to Controls collection so its UniqueID is null (or Nothing for VB
). So the example seems to use a negative proof method of explanation if it was intentionally.
Third and the last – name of property is UniqueID not UniqueId and whereas it is valid for VB
, C# variant of the example won’t compile.
Page 76. Last code block.
Misprint: C# variant of overridden property UniqueID has parentheses after property name.
Next to last code block on page 74 and first code block on page 77 have spaces inside name and id attributes values whereas they should literally reproduce HTML generated code.
Second code block on page 77 introduce an example of HTML generated by two instances of BookDetail control which contains buttons “Submit” and “Reset” (value attributes). But the second instance of the control has value attribute set to “on click” for both buttons. As it is supposed that we are generating this control completely in code it is unlikely that it was done intentionally.
Third paragraph on page 75 contains sentence:
quote:If the control is in a Panel on a user control, all three properties
point to different objects: the Page property points to the Page object, the Panel property points to the
Panel, and the NamingContainer points to the user control.
Misprint: Panel property points to the Panel
instead of Parent property points to the Panel
Once again sorry if I am wrong. Actually I think the book is great. Thank you.