2011-12-13 95 views
1

如何在顯示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到advoid重複的效果?

回答

1

您可以從服務器端訪問動畫屬性。所以你可能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財產,如果你需要將其還原更執着,但我認爲你的想法= )

+0

謝謝。你幫了我很多。 :) – user998405

+0

順便說一句如何恢復動畫? – user998405

+0

@ user998405很簡單 - >你可以將它存儲在你的代碼隱藏頁面的全局變量中(將它命名爲「onShownAnim」)。然後當你想恢復它。只需使用'modalPopup.OnShown = onShownAnim;'你的動畫就會回到 – jadarnel27

相關問題