Editor at Design Time
InfoImage
property is used to set the image URL for the Information. The special attribute of this code was the Editor
property which enables a window for navigating the local file images and selecting those images that we require:
true), Category("Information Details"), DefaultValue(""),
Editor("System.Web.UI.Design.ImageUrlEditor, System.Design,
Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a",
typeof(UITypeEditor))>
public string InfoImage{
get{
return this._InfoImage;
}
set{
this._InfoImage = value;
}
}
Rendering the Control
The control is rendered at design time which is very much similar to rendering at runtime. So the control is more like WYSIWYG, but much more easier and convenient:
protected override void Render(HtmlTextWriter output)
{
if(Enabled){
output.AddAttribute(HtmlTextWriterAttribute.Title,
ToolTip,false);
output.AddAttribute(HtmlTextWriterAttribute.Cellpadding,
this.Cellpadding,false);
output.AddAttribute(HtmlTextWriterAttribute.Cellspacing,
this.Cellspacing,false);
output.AddAttribute(HtmlTextWriterAttribute.Border,
BorderWidth.Value.ToString(),false);
output.AddAttribute(HtmlTextWriterAttribute.Bordercolor,
BorderColor.Name,false);
output.AddStyleAttribute(HtmlTextWriterStyle.BorderStyle,
BorderStyle.ToString());
output.AddAttribute(HtmlTextWriterAttribute.Bgcolor,
BackColor.Name,false);
output.AddAttribute(HtmlTextWriterAttribute.Width,
(Width.Value.ToString()+GetUnit(Width.Type)),false);
output.AddAttribute(HtmlTextWriterAttribute.Height,
(Height.Value.ToString()+GetUnit(Height.Type)),false);
output.AddAttribute(HtmlTextWriterAttribute.Class,
CssClass,false);
output.RenderBeginTag(HtmlTextWriterTag.Table);
RenderHeader(output);
RenderInfo(output);
if(IsDebug && Details.Length > 0){
RenderDetails(output);
}
output.RenderEndTag();
}
}
private void RenderHeader(HtmlTextWriter output){
output.RenderBeginTag(HtmlTextWriterTag.Tr);
output.AddAttribute(HtmlTextWriterAttribute.Bgcolor,
TdBackColor.Name,false);
output.AddAttribute(HtmlTextWriterAttribute.Rowspan,"2",
false);
output.AddAttribute(HtmlTextWriterAttribute.Width,"0%",
false);
output.AddAttribute(HtmlTextWriterAttribute.Height,"0%",
false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
switch(MsgType){
case MessageType.ERROR:
output.AddAttribute(HtmlTextWriterAttribute.Src,
ErrorImage,false);
break;
case MessageType.WARNING:
output.AddAttribute(HtmlTextWriterAttribute.Src,
WarningImage,false);
break;
default:
output.AddAttribute(HtmlTextWriterAttribute.Src,
InfoImage,false);
break;
}
output.RenderBeginTag(HtmlTextWriterTag.Img);
output.RenderEndTag();
output.RenderEndTag();
output.AddAttribute(HtmlTextWriterAttribute.Bgcolor,
TdBackColor.Name,false);
output.AddAttribute(HtmlTextWriterAttribute.Width,"100%",false);
output.AddAttribute(HtmlTextWriterAttribute.Height,"100%",false);
switch(MsgType){
case MessageType.ERROR:
output.AddAttribute(HtmlTextWriterAttribute.Class,
ErrorHeaderTextCss,false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(ErrorHeaderText);
output.RenderEndTag();
break;
case MessageType.WARNING:
output.AddAttribute(HtmlTextWriterAttribute.Class,
WarningHeaderTextCss,false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(WarningHeaderText);
output.RenderEndTag();
break;
default:
output.AddAttribute(HtmlTextWriterAttribute.Class,
InfoHeaderTextCss,false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(InfoHeaderText);
output.RenderEndTag();
break;
}
output.RenderEndTag();
}
private void RenderInfo(HtmlTextWriter output){
output.RenderBeginTag(HtmlTextWriterTag.Tr);
output.AddAttribute(HtmlTextWriterAttribute.Bgcolor,
TdBackColor.Name,false);
switch(MsgType){
case MessageType.ERROR:
output.AddAttribute(HtmlTextWriterAttribute.Class,
ErrorBreifTextCss,false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(Text);
output.RenderEndTag();
break;
case MessageType.WARNING:
output.AddAttribute(HtmlTextWriterAttribute.Class,
WarningBreifTextCss,false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(Text);
output.RenderEndTag();
break;
default:
output.AddAttribute(HtmlTextWriterAttribute.Class,
InfoBreifTextCss,false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(Text);
output.RenderEndTag();
break;
}
output.RenderEndTag();
}
private void RenderDetails(HtmlTextWriter output){
output.RenderBeginTag(HtmlTextWriterTag.Tr);
output.AddAttribute(HtmlTextWriterAttribute.Bgcolor,
TdBackColor.Name,false);
output.AddAttribute(HtmlTextWriterAttribute.Colspan,"2",false);
switch(MsgType){
case MessageType.ERROR:
output.AddAttribute(HtmlTextWriterAttribute.Class,
ErrorDetailsTextCss,false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(Details);
output.RenderEndTag();
break;
case MessageType.WARNING:
output.AddAttribute(HtmlTextWriterAttribute.Class,
WarningDetailsTextCss,false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(Details);
output.RenderEndTag();
break;
default:
output.AddAttribute(HtmlTextWriterAttribute.Class,
InfoDetailsTextCss,false);
output.RenderBeginTag(HtmlTextWriterTag.Td);
output.Write(Details);
output.RenderEndTag();
break;
}
output.RenderEndTag();
}