首页 新闻 搜索 专区 学院

.net控件开发 属性的取值 取不到?

0
悬赏园豆:10 [已关闭问题]

 

[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;
}
}

aspx
Code

Font_Family  set的时候是有值得,可就是保存不到viewstate中,也保存不到_font_family中,可是页面运行的时候getData()是去不到值的,帮帮忙,各位。

 

gzl的主页 gzl | 初学一级 | 园豆:5
提问于:2009-01-13 14:38
< >
分享
其他回答(1)
0

xuexixuexi...

Jared.Nie | 园豆:1940 (小虾三级) | 2009-01-13 19:42
0

是不是控件的问题啊?

shunan | 园豆:225 (菜鸟二级) | 2009-01-16 23:35
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册