I am creating Custom server control. In this control Have created properties for this control. I want create one property with the options value list. This values will be appear in property widow with drop down like border style of any control is appear in property window with the options like NotSet, None, Dotted, Solid...
namespace MessageControl
{
[DefaultProperty("MessageText")]
[ToolboxData("<{0}:MessageControl runat="server">")]
public class MessageControl : CompositeControl
{
public static string Error = "Error";
public static string Warning = "Warning";
public static string Success = "Success";
public static string Info = "Info";
public static List messagetypeOptions = new List { "Error","Success","Info","Warning"};
Literal ltrMessage = new Literal();
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("Custom MessageControl")]
[Localizable(true)]
public string MessageText
{
get
{
EnsureChildControls();
return ltrMessage.Text != null ? ltrMessage.Text: string.Empty;
}
set
{
ltrMessage.Text = value;
}
}
public enum Options
{
Error,
Success,
Info,
Warning
}
public virtual Options MessageType
{
get;
set;
}
protected override void CreateChildControls()
{
Controls.Clear();
ltrMessage.ID = "ltrMessageText";
this.Controls.Add(ltrMessage);
base.CreateChildControls();
}
protected override void OnPreRender(EventArgs e)
{
Page.ClientScript.RegisterClientScriptInclude("MessageControl", Page.ClientScript.GetWebResourceUrl(this.GetType(), "MessageControl.css.MessageControlCss.css"));
HtmlGenericControl cssLink = new HtmlGenericControl("link");
cssLink.ID = "MessageControlCssFile";
cssLink.Attributes.Add("href",Page.ClientScript.GetWebResourceUrl(GetType(),"MessageControl.css.MessageControlCss.css"));
cssLink.Attributes.Add("type","text/css");
cssLink.Attributes.Add("rel","StyleSheet");
Page.Header.Controls.Add(cssLink);
base.OnPreRender(e);
}
protected override void Render(HtmlTextWriter writer)
{
try
{
string type= MessageType.ToString().ToLower();
switch(type)
{
case "error":
writer.AddAttribute(HtmlTextWriterAttribute.Class, "error");
break;
case "info":
writer.AddAttribute(HtmlTextWriterAttribute.Class, "info");
break;
case "success":
writer.AddAttribute(HtmlTextWriterAttribute.Class, "success");
break;
case "warning":
writer.AddAttribute(HtmlTextWriterAttribute.Class, "warning");
break;
default:
writer.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "#FFF");
writer.AddStyleAttribute(HtmlTextWriterStyle.BorderColor, "#000");
break;
}
writer.RenderBeginTag(HtmlTextWriterTag.Div);
ltrMessage.RenderControl(writer);
writer.RenderEndTag();
}
catch (Exception ex)
{
}
}
}
}
Sir I am creating a custom server control for message. In this server control i have created one property MessageType and have created enum for the list of values for this property.
But I want list of strings for this property which i will select from dropdown when I use this control. or I can assign the value for this property code behinde(c#).
But by using enum I cant assign string value as MessageType="Error" or MessageType="Success" in cod