一个关于服务器端控件InputAttributes的怪问题,高手请进

lk0411 2008-07-10 02:43:13
.net2005
为了实现,radiobutton虽然不可用,但是字不是灰色。
大家可以建一个WEB项目,放一个radiobutton,放一个按钮(都是服务器端控件)
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.RadioButton1.InputAttributes.Add("disabled", "disabled");
}
else
{
//不写这句,页面第一次设置的InputAttributes马上失效,RadioButton1变得可用,反之不失效,不知道为什么。
AttributeCollection myAttributeCollection = this.RadioButton1.InputAttributes;
}
}
帮忙请大家给解释一下,就是怪,调试的时候InputAttributes集合中还是有东西的。
...全文
115 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
GengWH 2008-07-12
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e)
{
this.RadioButton1.InputAttributes.Add("disabled", "disabled");
}
SlaughtChen 2008-07-12
  • 打赏
  • 举报
回复
了解
yagebu1983 2008-07-11
  • 打赏
  • 举报
回复
还没玩过这东西呢!!!
UP!!!
manbufenglin 2008-07-11
  • 打赏
  • 举报
回复
动态添加属性时,需要维护控件状态!!

楼上正解!
amandag 2008-07-11
  • 打赏
  • 举报
回复
protected void Page_Load(object sender, EventArgs e) 
{
this.RadioButton1.InputAttributes.Add("disabled", "disabled");
}
toxxj 2008-07-11
  • 打赏
  • 举报
回复
AttributeCollection myAttributeCollection = null;

void Page_Load(object sender,EventArgs e)
{
myAttributeCollection = new AttributeCollection(ViewState);
Response.Write("<h3> AttributeCollection.AttributeCollection Sample </h3>");
if (!IsPostBack)
{
myAttributeCollection.Add("Color" ,"Color.Red");
myAttributeCollection.Add("BackColor","Color.blue");
Response.Write("Attribute Collection count before PostBack = " + myAttributeCollection.Count);
Response.Write("<br /><u><h4>Enumerating Attributes for CustomControl before PostBack</h4></u>");
IEnumerator keys = myAttributeCollection.Keys.GetEnumerator();
int i =1;
String key;
while (keys.MoveNext())
{
key = (String)keys.Current;
Response.Write(i + ". "+key + "=" + myAttributeCollection[key]+"<br />");
i++;
}
}
else
{
Response.Write("Attribute Collection count after PostBack = "+myAttributeCollection.Count);
Response.Write("<br /><u><h4>Enumerating Attributes for CustomControl after PostBack</h4></u>");
IEnumerator keys = myAttributeCollection.Keys.GetEnumerator();
int i =1;
String key;
while (keys.MoveNext())
{
key = (String)keys.Current;
Response.Write(i + ". "+key + "=" + myAttributeCollection[key]+"<br />");
i++;
}
}
}

sheng9hhd 2008-07-11
  • 打赏
  • 举报
回复
直接Attributes.add不行么?
Jinglecat 2008-07-11
  • 打赏
  • 举报
回复
1.

if (!IsPostBack)
{
// !IsPostBack 表示只有回发(所谓的第二次)的时候才会执行了
this.RadioButton1.InputAttributes.Add("disabled", "disabled");
}
else
{
//不写这句,页面第一次设置的InputAttributes马上失效,RadioButton1变得可用,反之不失效,不知道为什么。
AttributeCollection myAttributeCollection = this.RadioButton1.InputAttributes;
}


2.
protected void Page_Load(object sender, EventArgs e)
{
this.RadioButton1.InputAttributes.Add("disabled", "disabled");
}
skyaspnet 2008-07-11
  • 打赏
  • 举报
回复
我这试了,没试出来,帮顶
lk0411 2008-07-10
  • 打赏
  • 举报
回复
没人会吗?怎么没人来看看?

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧