Отключить анимацию модального всплывающего окна - PullRequest
1 голос
/ 13 декабря 2011

Как отключить эффект анимации, пока отображается 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 Ответ

2 голосов
/ 13 декабря 2011

Вы можете получить доступ к свойствам анимации со стороны сервера. Таким образом, вы можете установить для свойства 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, если вам нужно его восстановить, но я думаю, вы поняли идею =)

...