ASP: Extend control (ASCX) and access base markup file from subclass code
Posted
by Pathoschild
on Stack Overflow
See other posts from Stack Overflow
or by Pathoschild
Published on 2010-01-29T20:58:37Z
Indexed on
2010/03/17
5:01 UTC
Read the original article
Hit count: 409
Hello,
I'm building form validation controls for our C# ASP application. The bulk of the work is handled by a BaseValidator control (subclassing System.Web.UI.UserControl), which also has the markup for the validation output. This is then extended by subcontrols like PasswordValidator, that provides the Validate method and any extra fields needed by that validator control.
(The end goal is to have controls like <uc1:PasswordValidator ControlId="txtPassword" /> which we can plop into any form with minimum duplication.)
However, PasswordValidator.ascx.cs cannot access the form elements defined in BaseValidator.ascx; the only way I've found to do so is to duplicate the markup in each subcontrol's *.ascx file. How can I extend BaseValidator.ascx.cs and access BaseValidator.ascx's markup in the subclass?
© Stack Overflow or respective owner