开发者

Store controls' custom attributes in viewstate

开发者 https://www.devze.com 2023-03-27 13:53 出处:网络
I add \"readonly\" 开发者_JAVA百科attribute to ASP.NET controls in some event handlers. control.Attributes.Add(\"readonly\", \"readonly\");

I add "readonly" 开发者_JAVA百科attribute to ASP.NET controls in some event handlers.

control.Attributes.Add("readonly", "readonly");

But these attributes are not stored in viewstate and after postback these attributes are cleared. How can I make it stay after postback? Using control.ReadOnly = true; is not applicable because it makes control disabled and therefore ugly. Thank you everybody for help!


This is an example style applied to disabled input text...

<!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>

Tested on Google Chroome 13.0.782.112 on Windows 7.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号