why does Controls.Add(validator) called inside custom control adds the validator to the parent page?
there is a sample code for creating a custom textbox control with built in validation posted here Building ASP.NET TextBox with Integrated Validation And Switchable Input Modes. Inside the code there is a call to开发者_JAVA百科 Controls.Add(validator) which adds the asp.net validator control to the textbox. when the textbox is used on the page, the validator is rendered to the page although the validator is added to the textbox and not to the page! please explain
Where exactly are you expecting the validator to be rendered? Your question is somewhat confusing... every validator that must run client-side code on a given web form has to be rendered in the output stream sent to the client.
As far as the client's web browser is concerned, it knows nothing about what server-side control actually contains the validator. All it cares about is rendering what it finds between the <html> tags.
精彩评论