I am building a Extender control. This control derives from the normal Control. Its purpose is to inject some text before/after the specified target control. I imagine this to be similar to how the AJAX Calendar Extender works. So it has the property like TargetControlID
, etc etc.
I am not sure which event of the target control to hookup so that I can insert my comment before/after the control renders.
To pictorially represent what I am trying to accomplish:
I just want to put comments where the green dashes appear. Anyway I can control that...?
The source code I have tried working with so far...
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using System.IO;
namespace DropDownSubstitute
{
/// <summary>
///
/// </summary>
public class DropDownListExtender : Control
{
public string TargetControlID { get; set; }
System.Web.UI.WebControls.DropDownList _ddl;
protected override void OnInit(EventArgs e)
{
_ddl = this.Page.FindControl(this.TargetControlID) as DropDownList;
if(_ddl == null)
throw new InvalidOperationException("TargetControlID for DropDownListExtender must be a valid ASP.NET DropDownList control");
_ddl.PreRender += new EventHandler(RenderDropDown);
}
void RenderDropDown(object sender, EventArgs e)
{
//Desperately wanting to put a comment before the DropDownList renders
// to the response
}
}
}