NRabbit

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
VS2008如果直接设置文本框的Readonly=true,则会发生此问题,建议不要直接设置此属性,在C#里用TextBox.Attributes["readonly"] = "true";绑定该属性,问题即可解决。
在BasePage中重载OnPreRende事件中偷梁换柱,代码如下:
       protected override void OnPreRender(EventArgs e)
        {
           
            //将所有的TextBox设置ReadOnly=true的文本框,添加"readonly"Html的attribute
            foreach (System.Web.UI.Control _c in Page.Form.Controls)
            {
                if (_c is TextBox)
                {
                    TextBox _box = (TextBox)_c;
                    if (_box.ReadOnly)
                    {
                        _box.ReadOnly = false;
                        _box.Attributes["readonly"] = "true";
                    }
                }
            }

            base.OnPreRender(e);
        }
posted on 2009-03-27 11:48  kevin.nrabbit  阅读(445)  评论(0编辑  收藏  举报