Nir*_*iya 5 c# asp.net user-controls
我成功创建了一个用于显示错误消息的用户控件.现在一切正常但是当显示消息时,可以访问后台控件.如何禁用页面控件或页面单击或选择任何控件.当消息面板关闭时,它应该启用页面控件.
我找到了答案的朋友.
void DisableControls(Control parent, bool status)
{
foreach (Control c in parent.Controls)
{
if (c is DropDownList)
{
((DropDownList)(c)).Enabled = status;
}
if (c is Button)
{
((Button)(c)).Enabled = status;
}
if (c is TextBox)
{
((TextBox)c).Enabled = status;
}
if (c is RadioButton)
{
((RadioButton)c).Enabled = status;
}
if (c is ImageButton)
{
((ImageButton)c).Enabled = status;
}
if (c is CheckBox)
{
((CheckBox)c).Enabled = status;
}
if (c is DropDownList)
{
((DropDownList)c).Enabled = status;
}
if (c is HyperLink)
{
((HyperLink)c).Enabled = status;
}
if (c is GridView)
{
((GridView)c).Enabled = status;
}
if (c is Table)
{
((Table)c).Enabled = status;
}
if (c is Menu)
{
((Menu)c).Enabled = status;
}
if (c is TreeView)
{
((TreeView)c).Enabled = status;
}
}
}
Run Code Online (Sandbox Code Playgroud)
我明白了,您希望它表现得像模式对话框。可以通过简单的 html + javascript 来完成。您必须创建覆盖整个页面的透明 div 覆盖层,这样用户就不会单击控件,而是单击 div。Z-index 表示相对于其余控件的位置。
<!-- Div Overlay -->
<div id="div-overlay" style="position: absolute; height: 100%; width: 100%; z-index: 200; display: none; opacity: 0.0"></div>
<!-- Scripts to show/hide overlay -->
<script type="text/javascript">
function showOverlay() {
var e = document.getElementById('div-overlay');
e.style.display = 'block';
}
function hideOverlay() {
var e = document.getElementById('div-overlay');
e.style.display = 'none';
}
</script>
Run Code Online (Sandbox Code Playgroud)
希望能帮助到你。
| 归档时间: |
|
| 查看次数: |
2917 次 |
| 最近记录: |