禁用页面所有控件
2011-01-11 13:17
148 查看
今天写一个页面,页面内容一条记录的详细信息,我想给加上权限控制,有权限的可以修改,没有权限的把所有控件都给禁用了,只能浏览,网上找了找,找到两段代码,直接用上了。
个人感觉,方案二节省服务器资源,因为是JavaScript,在客户端执行;而方案一对页面文件的大小不会有大的影响,对于程序员开发来说简单快捷,当然,肯定会增加一部分的服务器资源消耗。
方案一:遍历页面的所有控件并禁用。
代码如下:
方案二:给页面加上一层半透明的div(转载自:http://hi.baidu.com/liuspring/blog/item/4157564a0ca8952709f7efe2.html)
代码如下:
我直接用的方案一,方案二只是把代码拷过来测试了一下,可以用的。
(注:代码是网上收集的,不是我的原创,写在这里只是为了做个笔记,以免用到了还要四处去找,呵呵)
个人感觉,方案二节省服务器资源,因为是JavaScript,在客户端执行;而方案一对页面文件的大小不会有大的影响,对于程序员开发来说简单快捷,当然,肯定会增加一部分的服务器资源消耗。
方案一:遍历页面的所有控件并禁用。
代码如下:
protected void DisableAllControls() { foreach (Control control in form1.Controls) { if (control is WebControl) { ((WebControl)control).Enabled = false; } else if (control is HtmlControl) { ((HtmlControl)control).Disabled = true; } } }
方案二:给页面加上一层半透明的div(转载自:http://hi.baidu.com/liuspring/blog/item/4157564a0ca8952709f7efe2.html)
代码如下:
<html> <head> <title>半透明div</title> <mce:style><!-- .#mask { visibility: hidden; background-color: #cccccc; left: 0px; position: absolute; top: 0px; background-image: none; filter: alpha(opacity : 50); } .#dialog { visibility: hidden; background-color: #f7fcfe; z-index: 100; width: 300px; height: 50px; position: absolute; text-align: center; font-size: 30px; color: #FF0000; font-weight: bold; vertical-align: middle; } --></mce:style><style mce_bogus="1">.#mask { visibility: hidden; background-color: #cccccc; left: 0px; position: absolute; top: 0px; background-image: none; filter: alpha(opacity : 50); } .#dialog { visibility: hidden; background-color: #f7fcfe; z-index: 100; width: 300px; height: 50px; position: absolute; text-align: center; font-size: 30px; color: #FF0000; font-weight: bold; vertical-align: middle; }</style> <mce:script language="javaScript"><!-- function show() { var d_mask=document.getElementById('mask'); var d_dialog = document.getElementById('dialog'); d_mask.style.width = document.body.clientWidth ; d_mask.style.height=document.body.clientHeight; //网页正文全文 //d_mask.style.width = document.body.scrollWidth ; //d_mask.style.height=document.body.scrollHeight; d_dialog.style.top = document.body.clientHeight / 2 - 60; d_dialog.style.left =document.body.clientWidth / 2 -100; d_mask.style.visibility='visible'; d_dialog.style.visibility='visible'; } function divBlock_event_mousedown() { var e, obj, temp; obj=document.getElementById('dialog'); e=window.event?window.event:e; obj.startX=e.clientX-obj.offsetLeft; obj.startY=e.clientY-obj.offsetTop; document.onmousemove=document_event_mousemove; temp=document.attachEvent?document.attachEvent('onmouseup',document_event_mouseup):document.addEventListener('mouseup',document_event_mouseup,''); } function document_event_mousemove(e) { var e, obj; obj=document.getElementById('dialog'); e=window.event?window.event:e; with(obj.style){ position='absolute'; left=e.clientX-obj.startX+'px'; top=e.clientY-obj.startY+'px'; } } function document_event_mouseup(e) { var temp; document.onmousemove=''; temp=document.detachEvent?document.detachEvent('onmouseup',document_event_mouseup):document.removeEventListener('mouseup',document_event_mouseup,''); } window.onresize = function() { var d_mask=document.getElementById('mask'); var d_dialog = document.getElementById('dialog'); d_mask.style.width = document.body.clientWidth ; d_mask.style.height=document.body.clientHeight; } // --></mce:script> </head> <div id ="mask"></div> <div id ="dialog" onmousedown="divBlock_event_mousedown()">处理中,请等待……</div> <body> <table border='0' width="100%" height="100%"> <tr> <td> 测试 </td> </tr> <tr> <td> <input type="button" value="显示div" onclick="show()" /> </td> </tr> </table> </body> </html>
我直接用的方案一,方案二只是把代码拷过来测试了一下,可以用的。
(注:代码是网上收集的,不是我的原创,写在这里只是为了做个笔记,以免用到了还要四处去找,呵呵)
相关文章推荐
- 禁用asp.net页面中的所有控件 设置本页所有控件的Enabled = false的方法
- JS禁用页面上所有控件的实现方法(附demo源码下载)
- JS禁用页面上所有控件的实现方法(附demo源码下载)
- 遍历页面内所有一类控件并做相关操作
- 得到页面所有的form内对象数值——————为一个控件加一个客户端属性
- 如何在ASP.NET下遍历指定页面上所有控件
- 本地连接属性页面部分控件被禁用的原因
- 递归输出ASP.NET页面所有控件的类型和ID
- 保留一下遍历页面所有控件的方法
- 递归禁用所有服务端控件
- 捕捉页面所有控件及控件绑定
- js 禁用所有表单控件
- 递归输出ASP.NET页面所有控件的类型和ID的代码
- crm4.0禁用所有控件
- 递归输出ASP.NET页面所有控件的类型和ID
- 如何在ASP.NET下遍历指定页面上所有控件
- 递归输出ASP.NET页面所有控件的类型和ID
- 遍历页面所有Textbox控件并给他赋值为string.empty
- 禁用页面及页面所有frame内的右键菜单
- ASP.NET 4 页面控件无法被禁用及产生aspNetDisabled处理方法