我在某些事件处理程序中向ASP.NET控件添加“只读”属性。
control.Attributes.Add("readonly", "readonly");
但是这些属性不会存储在viewstate中,并且回发后这些属性将被清除。回发后如何保留它?使用
control.ReadOnly = true;
不适用,因为它会使控件禁用,因此很难看。谢谢大家的帮助!
最佳答案
这是应用于禁用输入文本的示例样式...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type="text/css">
input[disabled]
{
background-color:White;
border:0 solid #fff;
color:red;
}
</style>
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="text" disabled="disabled" class="disabled" value="i'm disabled!"/>
</div>
</form>
</body>
</html>
已在Windows 7的Google Chroome 13.0.782.112上进行测试。
关于c# - 将控件的自定义属性存储在viewstate中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7022751/