62,046
社区成员
发帖
与我相关
我的任务
分享
<asp:ListBox ID="ListBox1" runat="server" SelectionMode="Multiple">
<asp:ListItem>item1</asp:ListItem>
<asp:ListItem>item2</asp:ListItem>
<asp:ListItem>item3</asp:ListItem>
</asp:ListBox>
/**
*Ivony... 13:53:25
*将Multiple的特性加一个 TypeConverter(typeof(MinimizableAttributeTypeConverter)),应该就可以了
*Ivony... 13:53:50
*我莫名其妙的得一大堆分,岂不是有倒分的嫌疑?
*维也纳(wien..) 13:54:28
*我把QQ的记录复制过去
*/
Ivony... 13:31:51
然后,我给SELECT加上disabled属性,这也是一个空值属性。
Ivony... 13:32:18
结果disabled属性不被智能提示所识别。
无论是设置disabled还是设置disabled="disabled",结果都是正确的。
Ivony... 13:33:33
然后我又在input上测试,确定disable="disabled"这样的表达式能够被Parser分析。
Ivony... 13:33:55
再查Input类型,确定Disabled是bool型。
Ivony... 13:34:29
至此,可以确定是微软没有在Select元素上采取特殊处理所造成的。
Ivony... 13:40:53
Disabled属性的定义在HtmlControl类。
Ivony... 13:41:18
[DefaultValue(false), WebCategory("Behavior"), TypeConverter(typeof(MinimizableAttributeTypeConverter)), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool Disabled
{
get
{
string str = this.Attributes["disabled"];
if (str == null)
{
return false;
}
return str.Equals("disabled");
}
set
{
if (value)
{
this.Attributes["disabled"] = "disabled";
}
else
{
this.Attributes["disabled"] = null;
}
}
}
Ivony... 13:41:47
看得出来Disabled属性值的获取和设置都是直接操作Attributes
Ivony... 13:44:09
而事实上几乎所有的Html控件的属性都是直接操作Attributes,如
Ivony... 13:44:16
[WebCategory("Appearance"), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), DefaultValue(-1)]
public int Size
{
get
{
string s = base.Attributes["size"];
if (s == null)
{
return -1;
}
return int.Parse(s, CultureInfo.InvariantCulture);
}
set
{
base.Attributes["size"] = HtmlControl.MapIntegerAttributeToString(value);
}
}
Ivony... 13:44:32
这是HtmlInputText的Size属性。
Ivony... 13:44:58
言归正传,HtmlSelect的Multiple属性是这么写的:
[WebCategory("Behavior"), DefaultValue(""), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public bool Multiple
{
get
{
string str = base.Attributes["multiple"];
if (str == null)
{
return false;
}
return str.Equals("multiple");
}
set
{
if (value)
{
base.Attributes["multiple"] = "multiple";
}
else
{
base.Attributes["multiple"] = null;
}
}
}
Ivony... 13:45:10
可以看得出来,与Disabled属性完全没有任何区别。
Ivony... 13:45:20
那么区别在哪里呢?
Ivony... 13:45:47
就是特性,这是HtmlControl.Disabled的特性:
[DefaultValue(false), WebCategory("Behavior"), TypeConverter(typeof(MinimizableAttributeTypeConverter)), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
Ivony... 13:46:12
这个是HtmlSelect.Multiple的:
[WebCategory("Behavior"), DefaultValue(""), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
Ivony... 13:46:47
TypeConverter(typeof(MinimizableAttributeTypeConverter))
这个TypeConverter,便是问题的关键。
Ivony... 13:47:27
这个TypeConverter的代码如下:
internal class MinimizableAttributeTypeConverter : BooleanConverter
{
// Methods
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string a = value as string;
if (a == null)
{
return base.ConvertFrom(context, culture, value);
}
return ((a.Length > 0) && !string.Equals(a, "false", StringComparison.OrdinalIgnoreCase));
}
}
Ivony... 13:49:14
结论,微软忘了给Multiple属性做TypeConverter从而导致了问题。
<input id="sb" checked="true" runat="server" type="radio" />