简体   繁体   中英

How to disable the controls in an ASP.NET page when the usercontrol is selected?

I Successfully created an user control for displaying Error message. now everything works fine but when the message is shown the background controls can be accessed. how to disable the page controls or page from clicking or selecting any controls. and when the message panel is closed it should enable the page controls.

i found the answer friends.

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

I see, you want it to behave like a modal dialog. It can be done via simple html + javascript. You must create a transparent div overlay that goes over the whole page, so the user instead of clicking the controls it would be clicking on the div. Z-index indicates the position over the rest of controls.

<!-- 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>

Hope it helps.

您可以使用简单的div并在CSS的帮助下,您可以像模式弹出窗口一样显示该div或只使用jquery模式弹出窗口http://jqueryui.com/demos/dialog/或asp.net ajaxcontrol工具包http: //www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx

Are you trying to create a modal dialog? If yes you can use the ModalPopupExtender Control from asp.net ajax. check this link:

http://msdn.microsoft.com/en-us/magazine/cc164247.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM