2010-12-11 3 views
5

나는 오류 메시지를 표시하기위한 사용자 정의 컨트롤을 성공적으로 만들었습니다. 이제 모든 것이 잘 작동하지만 메시지가 표시되면 배경 컨트롤에 액세스 할 수 있습니다. 페이지 컨트롤이나 페이지를 클릭하거나 컨트롤을 선택하지 못하게하는 방법. 메시지 패널이 닫히면 페이지 컨트롤이 활성화되어야합니다.usercontrol이 선택되었을 때 ASP.NET 페이지에서 컨트롤을 해제하는 방법은 무엇입니까?

대답 친구를 찾았습니다.

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

사용자 정의 컨트롤이 활성화 될 때 나는 내가 controls.but 컨트롤을 추가 한 div를 가지고 있는데, 호출 한 페이지의 컨트롤도 활성화되어 있습니다. 해당 페이지의 컨트롤을 비활성화하고 싶습니다. –

+0

다음과 같이 간단하게 코드를 크게 간소화 할 수 있습니다. foreach (parent.Controls에서 Control c) {c.Enabled = false; }'Enabled는'Control'의 속성이기 때문에. 답장을 보내 주셔서 감사합니다. – Crisfole

+0

나는 그것을 벌써 시도했다. 그러나 그것을 기울인다 can not는 그것을 성공하게한다. 오류가 발생합니다. –

답변

2

내가 볼을, 당신은 모달 대화처럼 행동하고 싶습니다. 그것은 간단한 HTML + 자바 스크립트를 통해 할 수 있습니다. 전체 페이지로 이동하는 투명한 div 오버레이를 만들어야하므로 사용자는 div를 클릭 할 컨트롤을 클릭하는 대신 Z- 색인은 나머지 컨트롤 위에 위치를 나타냅니다.

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

희망이 있습니다.

1

당신은 단순히 사업부를 사용할 수 있으며 CSS의 도움으로, 당신은 할 수 모달 팝업처럼 그 DIV를 표시하거나 사용할 수 있습니다 JQuery와 모달 http://jqueryui.com/demos/dialog/ 또는 asp.net의 ajaxcontrol 툴킷 http://www.asp.net/ajax/ajaxcontroltoolkit/samples/modalpopup/modalpopup.aspx

+0

아니요 페이지 깜박임과 같은 문제가있어서 AJAX를 사용하고 싶지 않습니다. –

+0

CSS를 사용하여 모달 팝업처럼 표시 한 다음 다른 모든 컨트롤에 액세스 할 수 없으면 JQuery를 사용하십시오. –

+0