Niranjan Thangaiya
Niranjan Thangaiya

Reputation: 515

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

Upvotes: 6

Views: 3344

Answers (3)

Luis Aguilar
Luis Aguilar

Reputation: 4371

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.

Upvotes: 3

subs
subs

Reputation: 2249

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

Upvotes: 1

Fraz Sundal
Fraz Sundal

Reputation: 10448

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

Upvotes: 2

Related Questions