禁用模式弹出扩展器的动画

时间:2011-12-13 03:43:38

标签: c# asp.net ajaxcontroltoolkit modalpopup

如何在显示ModalPopupExtender时禁用动画效果?这是我的编码:

HTML

 <script language ="javascript" type="text/javascript">
    function pageLoad() {
        var mpe = $find("modalPopUp");
        //add shown will be fire when when the ModalPopupExtender had shown 
        mpe.add_shown(onShown);

    }
    function onShown() {
        var background = $find("modalPopUp")._backgroundElement;
        background.onclick = function () { $find("modalPopUp").hide(); }
    }
 </script>

<asp:UpdatePanel ID ="updatePanel" runat="server">
    <ContentTemplate>
<asp:Panel ID="Panel1" runat="server" BackColor="Azure">
   <asp:UpdatePanel ID="updatePanel2" runat="server"  UpdateMode="Conditional">
   <ContentTemplate>


    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
    <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
    <br />
    <br />
    <br />
    <br />
    <br />

   </ContentTemplate>
   </asp:UpdatePanel>

</asp:Panel>


     <!--Register modal pop up-->
    <asp:ModalPopupExtender ID="modalPopUp" runat="server" 
    TargetControlID="Button1" PopupControlID="Panel1" 
    BackgroundCssClass="overlay_style" BehaviorID="modalPopUp"  >
       <Animations>
        <OnShown>
          <FadeIn duration="0.5" Fps="100" />
        </OnShown>
    </Animations>
        </asp:ModalPopupExtender>
<asp:Button ID="Button1" runat="server" Text="Button" />
</ContentTemplate>
    </asp:UpdatePanel>

我的后端代码:

 protected void Button2_Click(object sender, EventArgs e)
 {
     this.modalPopUp.Show();
 }

如何在点击button2以确定重复效果时禁用动画?

1 个答案:

答案 0 :(得分:2)

您可以从服务器端访问动画属性。所以你可以OnShown属性设置为null,这样它就不会重复(如果需要再次恢复,可能会将动画保存在变量中)。像这样:

protected void Button2_Click(object sender, EventArgs e)
{
    // Store the current "OnShown" animation for possible later use
    AjaxControlToolkit.Animation onShownAnim = modalPopup.OnShown;
    // Set the "OnShown" animation propert to null to disable the animation
    modalPopup.OnShown = null;

    modalPopup.Show(); // Now your popup shows without any animation, hooray!
}

关于onShownAnim的注意事项 - 如果你需要恢复它,你一定会想要使用比局部变量更持久的东西来保存当前的OnShown属性,但我认为你得到了idea =)