Hi friends,
I want to know that the method which must be overridden in a custom control?
Custom Control in ASP.NET
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 19, 2011, 7:34 AM EST
The key method of the custom control is Render. This method is declared in the base class, and must be overridden in your derived class if you wish to take control of rendering to the page.
Thanks
Anuja PawarRank #1,404 · 1.2K reputationPosted Dec 20, 2011, 1:05 AM EST
see this example, the Render method uses the HtmlTextWriter object passed in as a parameter to write the string held in the Text property
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
namespace CustomControls
{
[DefaultProperty("Text"), ToolboxData("<{0}:WebCustomControl1 runat=server>{0}:WebCustomControl1>")]
public class WebCustomControl1 : System.Web.UI.WebControls.WebControl {
private string text;
[Bindable(true), Category("Appearance"), DefaultValue("")]
public string Text {
get {
return text;
}
set {
text = value;
} }
protected override void Render(HtmlTextWriter output)
{
output.Write(Text);
}
}
}