【问题标题】:How to hide and view ModalPopupExtender?如何隐藏和查看 ModalPopupExtender?
【发布时间】:2015-05-16 05:04:46
【问题描述】:

我在项目的启动页面中使用 4 Modalpopupextender。当我运行我的启动页面时,即使在单击指定的 TargetControlID 之前,我在 Modalpopupextender 中的 PopupControlID 下设置的面板也是可见的。我试图将这些设置为 false,但它对我有帮助,我还尝试创建一个 css 类来在加载页面时隐藏面板,并在单击指定按钮时查看面板,但这对我没有帮助。请帮忙。谢谢你。

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<style type = "text/css">
        .hidePanel 
        {
            display:none;
        }
        .showpanel
        {
            display : block;
        }
    .panel
    {
        background : gray;
        padding : 10px;
    }
    div ul ul 
    {
        display: none;
    }
    div ul li:hover > ul 
    {
        display: block;
    }
    div ul li ul:hover > ul 
    {
        display: block;
    }
    </style>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:modalpopupextender ID="Modalpopupextender1" CancelControlID = "Button8" TargetControlID = "Button2" PopupControlID = "StaffSP" runat="server"></asp:modalpopupextender>
    <asp:modalpopupextender ID="Modalpopupextender2" CancelControlID = "Button10" TargetControlID = "Button3" PopupControlID = "StaffFP" runat="server"></asp:modalpopupextender>
    <asp:modalpopupextender ID="Modalpopupextender3" CancelControlID = "Button12" TargetControlID = "Button5" PopupControlID = "AdminSP" runat="server"></asp:modalpopupextender>
    <asp:modalpopupextender ID="Modalpopupextender4" CancelControlID = "Button14" TargetControlID = "Button6" PopupControlID = "AdminSP" runat="server"></asp:modalpopupextender>
    <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="XX-Large" Text="Automated Examination System"></asp:Label><br /> <br /><br /> 
    <asp:Panel ID = "Main" runat = "server" Height="181px" Width="275px">                                                                                                                         
    <ul>
    <li style="margin-removed 33px; width: 169px;"> <asp:LinkButton ID = "LinkAdmin" runat = "server" onclick="LinkAdmin_Click">Coordinator</asp:LinkButton></li>
    <li style="width: 172px; margin-removed 33px"> <asp:LinkButton ID="LinkStaff" runat="server" onclick="LinkStaff_Click">Staff</asp:LinkButton></li>
    <li style="margin-removed 33px"> <asp:LinkButton ID = "LinkStudent" runat = "server">Student</asp:LinkButton>
            <ul>
            <li><asp:LinkButton ID = "LinkButton1" runat = "server">Fresh Registration</asp:LinkButton></li>
            <li><asp:LinkButton ID = "LinkButton2" runat = "server">Re Registration</asp:LinkButton></li>
            </ul>
        </li>
    </ul>
    </asp:Panel>
    </div>
    <asp:Panel ID="StaffLogin" runat="server" Height="59px" 
        style="z-index: 1; left: 302px; top: 112px; position: absolute; height: 59px; width: 275px" 
        Visible="False" Width="275px">
        Staff<br />
        <asp:Button ID="Button1" runat="server" Text="Login" />
        <asp:Button ID="Button2" runat="server" Text="New Staff" />
        <asp:Button ID="Button3" runat="server" Text="Fogot Password" />
    </asp:Panel>
    <asp:Panel ID="AdminLogin" runat="server" 
        style="z-index: 1; left: 302px; top: 193px; position: absolute; height: 78px; width: 275px" 
        Visible="False" Width="275px">
        Admin<br />
        <asp:Button ID="Button4" runat="server" Text="Login" />
        <asp:Button ID="Button5" runat="server" Text="New Admin" />
        <asp:Button ID="Button6" runat="server" Text="Forgot Password" />
    </asp:Panel>
    <asp:Panel ID="StaffSP" runat="server" Height="48px" Width="274px">
        Staff SP<br />
        <asp:Button ID="Button7" runat="server" Text="Button" />
        <asp:Button ID="Button8" runat="server" Text="Cancel" />
    </asp:Panel>
    <asp:Panel ID="StaffFP" runat="server" Height="48px" Width="274px">
        Staff FP<br />
        <asp:Button ID="Button9" runat="server" Text="Button" />
        <asp:Button ID="Button10" runat="server" Text="Cancel" />
        <br />
        <br />
    </asp:Panel>
    <asp:Panel ID="AdminSP" runat="server" Height="48px" Width="274px">
        Admin SP<br />
        <asp:Button ID="Button11" runat="server" Text="Button" />
        <asp:Button ID="Button12" runat="server" Text="Cancel" />
        <br />
        <br />
    </asp:Panel>
    <asp:Panel ID="AdminFP" runat="server" Height="48px" Width="274px">
        AdminFP<br />
        <asp:Button ID="Button13" runat="server" Text="Button" />
        <asp:Button ID="Button14" runat="server" Text="Cancel" />

    </asp:Panel>

    </form>
</body>
</html>

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class TrailPopup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void LinkAdmin_Click(object sender, EventArgs e)
    {
        AdminLogin.Visible = true;
        StaffLogin.Visible = false;
    }
    protected void LinkStaff_Click(object sender, EventArgs e)
    {
        AdminLogin.Visible = false;
        StaffLogin.Visible = true;
    }
}

编辑:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<style type = "text/css">
        .hidePanel 
        {
            display:none;
        }
        .showpanel
        {
            display : block;
        }
    .panel
    {
        background : gray;
        padding : 10px;
    }
    div ul ul 
    {
        display: none;
    }
    div ul li:hover > ul 
    {
        display: block;
    }
    div ul li ul:hover > ul 
    {
        display: block;
    }
    </style>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="XX-Large" Text="Automated Examination System"></asp:Label><br />&nbsp;<br /><br />&nbsp;
    <asp:Panel ID = "Main" runat = "server" Height="181px" Width="275px">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <ul>
    <li style="margin-left: 33px; width: 169px;">&nbsp;<asp:LinkButton ID = "LinkAdmin" runat = "server" onclick="LinkAdmin_Click">Coordinator</asp:LinkButton></li>
    <li style="width: 172px; margin-left: 33px">&nbsp;<asp:LinkButton ID="LinkStaff" runat="server" onclick="LinkStaff_Click">Staff</asp:LinkButton></li>
    <li style="margin-left: 33px">&nbsp;<asp:LinkButton ID = "LinkStudent" runat = "server">Student</asp:LinkButton>
            <ul>
            <li><asp:LinkButton ID = "LinkButton1" runat = "server">Fresh Registration</asp:LinkButton></li>
            <li><asp:LinkButton ID = "LinkButton2" runat = "server">Re Registration</asp:LinkButton></li>
            </ul>
        </li>
    </ul>
    </asp:Panel>
    </div>
    <asp:Panel ID="StaffLogin" runat="server" Height="59px" 
        style="z-index: 1; left: 302px; top: 112px; position: absolute; height: 59px; width: 275px" 
        Visible="False" Width="275px">
        Staff<br />
        <asp:Button ID="Button1" runat="server" Text="Login" />
        <asp:Button ID="Button2" runat="server" Text="New Staff" />
        <asp:Button ID="Button3" runat="server" Text="Fogot Password" />
    </asp:Panel>
    <asp:Panel ID="AdminLogin" runat="server" style="left: 302px; top: 193px; position: absolute; height: 78px; width: 275px" Visible="False" Width="275px">Admin<br />
        <asp:Button ID="Button4" runat="server" Text="Login" />
        <asp:Button ID="Button5" runat="server" Text="New Admin" />
        <asp:Button ID="Button6" runat="server" Text="Forgot Password" />
    </asp:Panel>
    <asp:Panel ID="StaffSP" Visible = "false" runat="server" Height="48px" Width="274px">
        Staff SP<br />
        <asp:modalpopupextender ID="Modalpopupextender1" CancelControlID = "Button8" TargetControlID = "Button2" PopupControlID = "StaffSP" runat="server"></asp:modalpopupextender>
        <asp:Button ID="Button7" runat="server" Text="Button" />
        <asp:Button ID="Button8" runat="server" Text="Cancel" />
    </asp:Panel>
    <asp:Panel ID="StaffFP" Visible = "false" runat="server" Height="48px" Width="274px">
        Staff FP<br />
        <asp:modalpopupextender ID="Modalpopupextender2" CancelControlID = "Button10" TargetControlID = "Button3" PopupControlID = "StaffFP" runat="server"></asp:modalpopupextender>
        <asp:Button ID="Button9" runat="server" Text="Button" />
        <asp:Button ID="Button10" runat="server" Text="Cancel" />
        <br />
        <br />
    </asp:Panel>
    <asp:Panel ID="AdminSP" Visible = "false" runat="server" Height="48px" Width="274px">
        Admin SP<br />
        <asp:modalpopupextender ID="Modalpopupextender4" CancelControlID = "Button14" TargetControlID = "Button6" PopupControlID = "AdminSP" runat="server"></asp:modalpopupextender>
        <asp:Button ID="Button11" runat="server" Text="Button" />
        <asp:Button ID="Button12" runat="server" Text="Cancel" />
        <br />
        <br />
    </asp:Panel>
    <asp:Panel ID="AdminFP" Visible = "false" runat="server" Height="48px" Width="274px">
        AdminFP<br />
        <asp:modalpopupextender ID="Modalpopupextender3" CancelControlID = "Button12" TargetControlID = "Button5" PopupControlID = "AdminFP" runat="server"></asp:modalpopupextender>
        <asp:Button ID="Button13" runat="server" Text="Button" />
        <asp:Button ID="Button14" runat="server" Text="Cancel" />

    </asp:Panel>

    </form>
</body>
</html>

【问题讨论】:

  • 提供你的aspx代码

标签: c# asp.net ajax


【解决方案1】:

在用于modalpopupextender控件的每个PopupControl中调用你的css类隐藏面板:

  `<asp:Panel ID="StaffSP" runat="server" CssClass="hide" Height="48px" Width="274px" >
    Staff SP<br />
    <asp:Button ID="Button7" runat="server" Text="Button" />
    <asp:Button ID="Button8" runat="server" Text="Cancel" />
</asp:Panel>
<asp:Panel ID="StaffFP" runat="server" Height="48px" Width="274px" style="display:none;">
    Staff FP<br />
    <asp:Button ID="Button9" runat="server" Text="Button" />
    <asp:Button ID="Button10" runat="server" Text="Cancel" />
    <br />
    <br />
</asp:Panel>
<asp:Panel ID="AdminSP" runat="server" Height="48px" Width="274px" CssClass="hidePanel">
    Admin SP<br />
    <asp:Button ID="Button11" runat="server" Text="Button" />
    <asp:Button ID="Button12" runat="server" Text="Cancel" />
    <br />
    <br />
</asp:Panel>
<asp:Panel ID="AdminFP" runat="server" Height="48px" Width="274px" Visible="false">
    AdminFP<br />
    <asp:Button ID="Button13" runat="server" Text="Button" />
    <asp:Button ID="Button14" runat="server" Text="Cancel" />

</asp:Panel>`

【讨论】:

  • Rojalin,我已经这样做了。但这会在我运行启动页面时隐藏面板,但在单击指定按钮时不会触发。
  • 指定按钮(链接按钮)??我在我的系统上运行代码并在单击链接按钮时给出结果
  • 不,指定的按钮不是链接按钮。这些链接按钮仅用于分类人员登录和协调员登录。当您单击人员链接按钮时,将显示一个面板,您可以在其中找到 3 个按钮,即登录、新员工和忘记密码(不是链接按钮)。当你点击newstaff或忘记密码从面板可见时,它必须弹出modalpopupextender中popcontrolid下指定的相应面板。
  • 请使用 style 作为 display:none 而不是在您的面板控件中可见,那么您的问题将得到解决。检查这个:&lt;asp:Panel ID="StaffSP" runat="server" CssClass="modalPopup" Height="48px" Width="274px" style="display:none;"&gt; Staff SP&lt;br /&gt; &lt;asp:Button ID="Button7" runat="server" Text="Button" /&gt; &lt;asp:Button ID="Button8" runat="server" Text="Cancel" /&gt; &lt;/asp:Panel&gt;
【解决方案2】:

您已将所有 4 个 TargetControlID 放入不可见的面板中

【讨论】:

  • 即使这点帮助了我:(。我已经按照你在编辑部分的建议发布了代码。请看一下。
  • 尝试了您的代码,几乎没有更改,它在我身边工作
  • 将 CssClass="modalPopup" Style="display: none" 添加到所有 PopupControls ,将 BackgroundCssClass="modalBackground" 添加到所有 ModalPopupExtender ,以下是 css .modalBackground { background-color: Black;过滤器:阿尔法(不透明度= 90);不透明度:0.8; } .modalPopup { 背景颜色:#FFFFFF;边框宽度:3px;边框样式:实心;边框颜色:黑色;上边距:10px;左边距:10px;宽度:300px;高度:140px;}
  • 非常感谢朋友。你解决了我的问题。再次感谢您:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-11
  • 2011-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多