简体   繁体   English

UserControl 阻止/隐藏/覆盖页面上的所有其他控件

[英]UserControl to block/hide/overlay all other controls on the page

Say I've made a user control.假设我做了一个用户控件。 I want it to have following behavior:我希望它具有以下行为:

  1. When its Visible property is true , users can only operate things inside it, but not anything outside of it, ie any other control in its containing user controls (if any) and the page is not accessible to users.当它的Visible属性为true时,用户只能操作它内部的东西,而不能操作它之外的任何东西,即它包含的用户控件(如果有的话)中的任何其他控件,并且用户不能访问该页面。 (Even better if they'd also be invisible to users.) (如果用户也看不到它们就更好了。)
  2. The above effect lasts between postbacks, until its Visible is changed to false .上述效果在回发之间持续,直到其Visible更改为false When that happens, this user control is invisible to users, and stuff outside it are back to their normal state.当这种情况发生时,这个用户控件对用户是不可见的,它之外的东西又恢复到正常的 state。

How can this be achieved?如何实现?

One nice way would be to say have the UC in a div.一种不错的方法是将 UC 放在一个 div 中。 You then pop the div with a dialog (jquery.UI dialog).然后使用对话框(jquery.UI 对话框)弹出 div。 When such a dialog is display, then the screen background goes gray, and only the control is visible.当显示这样的对话框时,屏幕背景变为灰色,只有控件可见。 And if you click/use any button in that control that causes a page post-back, then it will collapse, disappear, and the page is back to normal with user being able to use.如果您单击/使用该控件中导致页面回发的任何按钮,那么它将折叠、消失,并且页面恢复正常,用户可以使用。

The effect looks like this:效果看起来像这样:

here is a GV to edit data.这是一个编辑数据的 GV。 When I hit edit button, I display my UC (to edit the one row).当我点击编辑按钮时,我会显示我的 UC(编辑一行)。

So, this grid:所以,这个网格:

在此处输入图像描述

so, this is a round about way to acheive your goal.因此,这是实现目标的一种迂回方式。 By popping a div (with the UC inside), then we solue the "UI" for the user, focus for user in/on/looking at the pop dialog, and better yet, the whole screen background goes gray, and the user cannot select/use/click on any control on the page.通过弹出一个 div(里面有 UC),然后我们为用户解决“UI”,让用户在/在/查看弹出对话框时获得焦点,更好的是,整个屏幕背景变灰,用户无法选择/使用/单击页面上的任何控件。

The above idea might not work for you, but if it can be adopted, then all of your messay code and handstands to disable the rest of the page is automatic done for you.上面的想法可能不适合你,但如果它可以被采纳,那么你所有的messay代码和倒立禁用页面的rest都是自动为你完成的。

As noted, we all quite much have jQuery installed.如前所述,我们都安装了 jQuery。 You have to add jQuery.UI.您必须添加 jQuery.UI。

the code to pop the above dialog is thus then this:因此,弹出上述对话框的代码是这样的:

   <script>
       function popedit() {

            MyPWidth = "62em"
            MyWidth = $(window).width()

            if (MyWidth < 840) {
                MyPWidth = (MyWidth - 25)  + 'px'
            }

            var myDialog = $("#EditRecord");
            myDialog.dialog({
                title: "Edit Hotel",
                width: MyPWidth,
                modal: true,
                appendTo: "form",
                dialogClass : "dialogWithDropShadow",
                close: myclose
            });
       }

So, above pops the "div" called EditRecord, and it does the rest for you.因此,上面弹出名为 EditRecord 的“div”,它会为您执行 rest。

It turned out to be actually pretty easy:事实证明这实际上很容易:

Lay a <div class="overlay"></div> as the topmost element inside the user control, enclosing any other elements and child controls.放置一个<div class="overlay"></div>作为用户控件内的最顶层元素,包围所有其他元素和子控件。 And define a .overlay class in the site CSS stylesheet as something like this:并在站点 CSS 样式表中定义.overlay class 如下所示:

position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.5);
overflow: auto;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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