gpt4 book ai didi

c# - 选择用户控件时如何禁用 ASP.NET 页面中的控件?

转载 作者:太空狗 更新时间:2023-10-29 23:34:41 25 4
gpt4 key购买 nike

我成功地创建了一个用于显示错误消息的用户控件。现在一切正常,但是当显示消息时,可以访问后台控件。如何禁止页面控件或页面单击或选择任何控件。当消息面板关闭时,它应该启用页面控件。

我找到了答案 friend 。

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;
}
}
}

最佳答案

我明白了,您希望它表现得像模态对话框。它可以通过简单的 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>

希望对您有所帮助。

关于c# - 选择用户控件时如何禁用 ASP.NET 页面中的控件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4417101/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com