Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
                    } 
}
        }
like image 227
Niranjan Thangaiya Avatar asked Oct 26 '22 00:10

Niranjan Thangaiya


2 Answers

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.

like image 58
Luis Aguilar Avatar answered Nov 15 '22 06:11

Luis Aguilar


You can use simply a div and with the help of CSS, you can able to display that div like a modal popup or simply use jquery modal popup http://jqueryui.com/demos/dialog/ or asp.net ajaxcontrol toolkit http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx

like image 39
Fraz Sundal Avatar answered Nov 15 '22 06:11

Fraz Sundal