【问题标题】:Fancybox pop up opens automaticly after postbackFancybox 弹出窗口在回发后自动打开
【发布时间】:2014-03-18 22:18:42
【问题描述】:

我用过这样的花哨的弹出框

 <div class="x-popup" id="PopUpWarning">
            <table cellspacing="0" cellpadding="0" class="info" width="100%">
                <tr>
                    <td align="center" valign="middle" height="175">
                        <asp:Label ID="lblWarning" runat="server" Text="You must choose less than 256 item in the following fields :"></asp:Label>
                        <telerik:RadListView ID="lvWarningFields" runat="server" ItemPlaceholderID="itemTemplate">
                            <LayoutTemplate>
                                <div>
                                    <ul>
                                        <asp:PlaceHolder ID="itemTemplate" runat="server"></asp:PlaceHolder>
                                    </ul>
                                </div>
                            </LayoutTemplate>
                            <ItemTemplate>
                                <li>
                                    <asp:Label ID="lblWarning" runat="server"><%# Container.DataItem %></asp:Label>
                                </li>
                            </ItemTemplate>
                        </telerik:RadListView>
                    </td>
                    <td>
                </tr>
            </table>
            <div class="bottom-buttons cf">
                <div class="fr">
                    <a href="#" class="button cancel">Cancel</a>
                </div>

            </div>
        </div>

我在代码后面的按钮单击事件中打开了幻想框弹出窗口。像这样

c#端

string jsWarning = "<script language='javascript' type='text/javascript'>Sys.Application.add_load(showWarning);</script>";
ClientScript.RegisterStartupScript(this.GetType(), "showWarning", jsWarning);

aspx 端

function showWarning() {
            show_popup('PopUpWarning');
        };

我在按钮事件中打开弹出窗口。并单击关闭按钮调用 $.fancybox.close();并弹出关闭。但是在同一页面回发后弹出窗口会自动打开。

我想我需要删除 Sys.Application.add_load(showWarning);脚本?是真的吗?

为什么我的弹出窗口在回发后打开。我需要打开仅弹出按钮单击触发。我该怎么做?

【问题讨论】:

  • 是否有任何理由将 javascript 事件绑定到后面代码中的按钮?如果您只是在您的 aspx 页面上添加适当的 onClick 事件,事情可能会容易得多。您愿意详细说明您的实施吗?
  • 因为我用的是fancybox。在该示例中,花式框弹出窗口仅使用 js 打开,“show_popup”调用了 fancybox.js 中的函数。我们无法从服务器端打开 fancybox。但是我需要在一些服务器端操作后打开fancybox pop up。所以我需要从服务器端调用js。

标签: c# javascript jquery asp.net fancybox


【解决方案1】:

将下面的代码保留在 aspx 页面中。

<script type="text/javascript">
function showWarning() {
        show_popup('PopUpWarning');
    };
</script>

点击下面的C#按钮调用函数

ScriptManager.RegisterStartupScript(this, this.GetType(), "showWarning", "showWarning();", true);

【讨论】:

  • 我试过这个。它解决了我的问题,但出现了另一个问题。当我的弹出窗口打开时,我意识到弹出窗口的形状不是很好。弹出窗口失去了自己的形状?
  • 可能是css问题。好的,首先将弹出代码拉入带有一些数据的纯 html 页面,并在运行 aspx 页面的同一浏览器中运行。如果发现任何问题,请解决问题。
  • 没有任何改变。如果我使用tring jsWarning = ""; ClientScript.RegisterStartupScript(this.GetType(), "showWarning", jsWarning);弹出以自己的形状打开。但是如果我使用 criptManager.RegisterStartupScript(this, this.GetType(), "showWarning", "showWarning();", true);它失去了自己的形状
  • ScriptManager.RegisterStartupScript(this.GetType(), "showValidation", "$(function(){showValidation();});", true);修复了css问题。谢谢苏尼尔。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-01-07
  • 1970-01-01
  • 2015-07-02
相关资源
最近更新 更多