[Bindable(true)]
[Category("Appearance")]
[Localizable(true)]
[DefaultValue("")]
public string Text
{
get
{
if (EnableViewState && ViewState["Text"] != null)
{
return (String)ViewState["Text"];
}
return string.Empty;
}
set
{
if(EnableViewState)
ViewState["Text"] = value;
}
}
private string _font_family = string.Empty;
[Bindable(true)]
[Category("Appearance")]
[Localizable(true)]
[Description("字体库")]
[Editor(typeof(FontCollectionEditor), typeof(UITypeEditor))]
public string Font_Family
{
get
{
if (EnableViewState && ViewState["Font_Family"] != null)
return (string)ViewState["Font_Family"];
return _font_family;
}
set
{
if (EnableViewState)
ViewState["Font_Family"] = value;
_font_family = value;
}
}
protected override void RenderContents(HtmlTextWriter output)
{
output.Write(getData());
}
private string getData()
{
StringBuilder sb = new StringBuilder();
sb.Append("text:"+Text+":text");
sb.Append("<select id=\"SelectFont\" style=\"width: 100px; height: 20px\">");
sb.Append("<option>字体</option>");
if (string.IsNullOrEmpty(Font_Family))
foreach (string f in Font_Family.Split(','))
sb.Append("<option>" + f + "</option>");
if (string.IsNullOrEmpty(_font_family))
foreach (string f in _font_family.Split(','))
sb.Append("<option>" + f + "</option>");
sb.Append("</select>");
sb.Append("字数限制为" + Fonts_Count.ToString());
return sb.ToString();
}
class FontCollectionEditor : CollectionEditor
{
public FontCollectionEditor(Type type) : base(type)
{
}
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService service = (IWindowsFormsEditorService) provider.GetService(typeof (IWindowsFormsEditorService));
FortsForm ff = new FortsForm("");
service.ShowDialog(ff);
string data = ff.data;
ff.Dispose();
if (!string.IsNullOrEmpty(data))
{
return data;
}
return string.Empty;
}
}
Code
Font_Family set的时候是有值得,可就是保存不到viewstate中,也保存不到_font_family中,可是页面运行的时候getData()是去不到值的,帮帮忙,各位。
xuexixuexi...
是不是控件的问题啊?