I have a custom ASP.NET control that derives from Panel.
It has a default constructor and the RenderBeginTag, RenderContents and RenderEndTag overrides.
Now in the constructor i want to check a few properties and in a certain case i want to prevent /cancel the complete rendering of the control.
What would be the easiest way to do this? Preferably just right there in that constructor. Right now i have added a small check to all override methods, but i’m sure this can be done a bit smarter.
Also you could override the
WebControl.Rendermethod to perform your check – this way you don’t have to check in 3 different methods.But a better solution would be to set
this.Visible = false– this prevents the render methods from being called and also preventsPreRenderevents from being raised (they by design should be only raised on visible controls).I would override the
Visibleproperty and add the check there: