ModalPopupExtender使用技巧( operate ModalPopupExtender by JavaScript)

 

ModalPopupExtender是个非常好用的AJAX控件, 网上有很多教程,但大多没有提起它的一些使用技巧:

 

1.简单应用:

 

常用属性:

      TargetControlID:用于触发弹出面板的控件。
      OkControlID:弹出面板中的确认按钮,用于确认新的样式。
       OnOkScript:当单击确认按钮后,关闭样式面板后,执行脚本。
      CancelControlID:样式面板中的取消按钮,用于取消应用样式。
      PopupDragHandleControlID:样式面板中用于触发面板的控件。
      DropShadow:样式面板是否有阴影。值为True,则有阴影;值为False,则没有阴影。
      BackgroundCssClass:样式面板中应用的css样式。

 

最简单的应用示例:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default6.aspx.cs" Inherits="Default6" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title>Untitled Page</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<asp:ScriptManager ID="ScriptManager1" runat="server">
    
</asp:ScriptManager>
    
<div>
    
        
<asp:Button ID="Button1" runat="server" Text="Button" />
        
<cc1:ModalPopupExtender ID="Button1_ModalPopupExtender" runat="server" 
            DynamicServicePath
="" Enabled="True" TargetControlID="Button1" PopupControlID="Panel1">
        
</cc1:ModalPopupExtender>
    
    
</div>
    
<asp:Panel ID="Panel1" runat="server" Height="176px" Width="141px">
    
</asp:Panel>
    
</form>
</body>
</html>

 

2.半透明阴影遮罩

要为ModalPopupExtender添加半透明阴影,就像官方网站上的案例一样,需要定义一个CSS类,并指派到BackgroundCssClass属性上

半透明背景css可以如下:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
    <style type="text/css">
        .bg
        
{
            position
: absolute;
            z-index
: 100;
            top
: 0px;
            left
: 0px;
            background-color
: #000;
            filter
: alpha(opacity=60);
            -moz-opacity
: 0.6;
            opacity
: 0.6;
        
}
    </style>

 

3.JavaScript 控制

 

如果我们需要用JavaScript控制弹出层的 show/hide ,使用以下代码即可:

 

    $find( ' Panel1 ' ).hide()
    $find(
' Panel1 ' ).show()

 

前提是,PopupControlID和BehaviorID都要是Panel1

完整代码如下:

 

ContractedBlock.gif ExpandedBlockStart.gif Code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="modalpopup.aspx.cs" Inherits="modalpopup" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
<title>Untitled Page</title>
    
<style type="text/css">
        .bg
        
{
            position
: absolute;
            z-index
: 100;
            top
: 0px;
            left
: 0px;
            background-color
: #000;
            filter
: alpha(opacity=60);
            -moz-opacity
: 0.6;
            opacity
: 0.6;
        
}
    
</style>

    
<script language="javascript" type="text/javascript">
// <!CDATA[

function Button2_onclick() {
//    $find('Panel1').hide()
    $find('Panel1').show()
}

// ]]>
    </script>

</head>
<body>
    
<form id="form1" runat="server">
    
<asp:ScriptManager ID="ScriptManager1" runat="server">
    
</asp:ScriptManager>
    
<div>
    
</div>
    
<p>
        
&nbsp;</p>
    
<p>
        
<asp:Button ID="Button1" runat="server" Text="Button" />
    
</p>
    
<asp:Panel ID="Panel1" runat="server" Height="156px" Width="127px">
        
<asp:Image ID="Image1" runat="server" Height="149px" ImageUrl="~/head_7953l61.jpg"
            Width
="123px" />
    
</asp:Panel>
    
<cc1:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server" DynamicServicePath=""
        BehaviorID
="Panel1" BackgroundCssClass="bg" PopupControlID="Panel1" Enabled="True" TargetControlID="Button1">
    
</cc1:ModalPopupExtender>
    
</form>
    
<p>
        
<input id="Button2" type="button" value="button" onclick="return Button2_onclick()" /></p>
</body>
</html>

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值