ASP.NET 控件不用Disabled实现ReadOnly的效果,即字体不变灰色。
2015-09-23 10:33
645 查看
最近,在一个asp.net项目中遇到RadioButtonList等控件设置Enabled=False时(只读状态),在IE浏览器中查看是字体颜色为灰,内容不清晰,尝试各种css效果失败,又在网上搜索近一天,终于发现以下方法有效。
参考引用:
</select>
同理,在ASP.NET中的应用
在asp.net页面中针对RadioButtonLis、RadioButton、DropDownList、HtmlSelect等控件标签中添加onmouseover="this.setCapture()" onmouseout="this.releaseCapture()"即可(字体颜色也可以直接设置或通过css设置了)。
如:
<asp:RadioButtonList ID="rdoP_Type" runat="server" RepeatColumns="2" RepeatLayout="Flow" onmouseover="this.setCapture()" onmouseout="this.releaseCapture()" ForeColor="#FF9966">
<asp:ListItem Value="Y">是 </asp:ListItem>
<asp:ListItem Value="N">否 </asp:ListItem>
</asp:RadioButtonList>
在程序中,可以这样添加:
以VB.NET为例:
rdoP_Type.Attributes.Add("onmouseover","this.setCapture()")
rdoP_Type.Attributes.Add("onmouseout","this.releaseCapture()")
分别在IE和FF浏览器下测试,发现IE测试没问题,但是FF并不支持(setCapture和releaseCapture,FF有自己的),再加个属性试试,变成这样
rdoP_Type.Attributes.Add("onmouseover","this.setCapture()")
’IE支持,FF不支持
rdoP_Type.Attributes.Add("onmouseout","this.releaseCapture()") ’IE支持,FF不支持
rdoP_Type.Attributes.Add("onclick","return false")
‘让FF支持
多个控件的情况下,可以通过遍历设置属性:
For Each t As Control In Controls
If TypeOf (t) Is RadioButtonList Then
Dim t1 As RadioButtonList = CType(t, RadioButtonList)
t1.Attributes.Add("onmouseover","this.setCapture()")
t1.Attributes.Add("onmouseout","this.releaseCapture()")
t1.Attributes.Add("onclick","return false")
End If
Next
在此之前,试过其他方法,不太理想,在此记录一下,以备需要时参考:
t1.Attributes.Add("style", "color:blue") 'FF支持,IE不兼容
t1.Attributes.Add("onclick", "return false")
t1.Attributes.Add("onclick", "this.checked=!this.checked") ’
t1.Attributes.Add("onclick", " if(rdoP_Type_0.checked) rdoP_Type_1.checked=!rdoP_Type_1.checked;") ‘有些效果,但需要继续完善判定方法。
参考引用:
HTML中Select不用Disabled实现ReadOnly的效果-javascript技巧
<select onbeforeactivate="return false" onfocus="this.blur()" onmouseover="this.setCapture()" onmouseout="this.releaseCapture()"> <option>1</option></select>
同理,在ASP.NET中的应用
在asp.net页面中针对RadioButtonLis、RadioButton、DropDownList、HtmlSelect等控件标签中添加onmouseover="this.setCapture()" onmouseout="this.releaseCapture()"即可(字体颜色也可以直接设置或通过css设置了)。
如:
<asp:RadioButtonList ID="rdoP_Type" runat="server" RepeatColumns="2" RepeatLayout="Flow" onmouseover="this.setCapture()" onmouseout="this.releaseCapture()" ForeColor="#FF9966">
<asp:ListItem Value="Y">是 </asp:ListItem>
<asp:ListItem Value="N">否 </asp:ListItem>
</asp:RadioButtonList>
在程序中,可以这样添加:
以VB.NET为例:
rdoP_Type.Attributes.Add("onmouseover","this.setCapture()")
rdoP_Type.Attributes.Add("onmouseout","this.releaseCapture()")
分别在IE和FF浏览器下测试,发现IE测试没问题,但是FF并不支持(setCapture和releaseCapture,FF有自己的),再加个属性试试,变成这样
rdoP_Type.Attributes.Add("onmouseover","this.setCapture()")
’IE支持,FF不支持
rdoP_Type.Attributes.Add("onmouseout","this.releaseCapture()") ’IE支持,FF不支持
rdoP_Type.Attributes.Add("onclick","return false")
‘让FF支持
多个控件的情况下,可以通过遍历设置属性:
For Each t As Control In Controls
If TypeOf (t) Is RadioButtonList Then
Dim t1 As RadioButtonList = CType(t, RadioButtonList)
t1.Attributes.Add("onmouseover","this.setCapture()")
t1.Attributes.Add("onmouseout","this.releaseCapture()")
t1.Attributes.Add("onclick","return false")
End If
Next
在此之前,试过其他方法,不太理想,在此记录一下,以备需要时参考:
t1.Attributes.Add("style", "color:blue") 'FF支持,IE不兼容
t1.Attributes.Add("onclick", "return false")
t1.Attributes.Add("onclick", "this.checked=!this.checked") ’
t1.Attributes.Add("onclick", " if(rdoP_Type_0.checked) rdoP_Type_1.checked=!rdoP_Type_1.checked;") ‘有些效果,但需要继续完善判定方法。
相关文章推荐
- [ASP.NET]分析MVC5源码,并实现一个ASP.MVC
- 我的ASPxGridView控件的数据是在后台绑定的,但是实现不了筛选和分页的功能,只能显示一页的数据?
- ASP.NET MVC Razor 输出没有编码的HTML字符串
- 如何对ASP.NET网站实现静态化
- asp.net快速连接access
- asp.net判断session过期
- asp.net mvc Ajax.BeginForm不能异步刷新,或转到新页面,或页面还是刷新了,的原因(或解决办法)
- ASP.NET MVC3 Model验证总结
- ASP.NET用户控件如何使用
- ASP.NET网站导航及导航控件如何使用
- ASP.NET(C#)读取Excel
- ASP.NET FileUpload读取上传文件的内容
- ASP.NET本质论阅读----线程与异步
- asp.net简单的登陆界面
- Spring AspectJ AOP 完整示例
- ASP.NET MVC 3 Razor 视图引擎 基本语法
- ASP.NET MVC 3 Razor 视图引擎 基本语法
- ASP.NET MVC 3 初认知
- ASP.NET MVC 3 初认知
- Asp.net Page_ClientValidate 的应用和跳过