2

我在 ASP.NET/C# 中有这个脚本——我试图控制何时显示气球弹出窗口,作为初步测试,我特别指示弹出窗口扩展器在任何情况下都不显示。

但它仍然显示在点击..

如何告诉 BalloonPopupExtender 禁用自身而不显示?

(稍后我想再次启用它来显示 - 但该信息只是为了完成我为什么首先想要它在那里..)

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Test Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        <asp:Panel ID="Panel1" runat="server">
            Balloon Information1
        </asp:Panel>
        <ajaxToolkit:BalloonPopupExtender ID="BalloonPopupExtender1" runat="server" BalloonPopupControlID="Panel1" TargetControlID="Label1" 
            DisplayOnClick="False" DisplayOnFocus="False" DisplayOnMouseOver="False"></ajaxToolkit:BalloonPopupExtender>
    </div>
    </form>
</body>
</html>
4

3 回答 3

1

I believe this is a bug in AjaxControlToolkit. Check this file: BalloonPopupExtenderBehavior.pre.js

As you can see, in the initialize function, click event handler added to target control only if _displayOnClick field value is true. Quite strange, as you specified false for server property that must be saved to that field. But if you'll check the set_displayOnClick function below in this extender, you'll find that value sent from server saved to this.displayOnClick field (without leading underscore). And since the _displayOnClick field have default value true (check constructor), its unable to turn off showing of baloon on click.

You can download toolkit sources from Codeplex, fix this file, rebuild solution and use custom toolkit library.

For a quick dirty fix you can add at page's bottom this placeholder bith script inside:

<asp:PlaceHolder runat="server" ID="FixScripotPlaceholder">
    <script type="text/javascript">
        function disableBaloon() {
            var extender = $find("BaloonExtender");
            $removeHandler(extender.get_element(), "click", extender._clickHandler);
        }

        setTimeout(disableBaloon, 500);
    </script>
</asp:PlaceHolder>

Setting Visible="false" for this placeholder you'll enable baloon on click from server code. Also from javascript you can use this script to enable baloon on click:

function enableBaloon(){
    var extender = $find("Extender's BehaviorID");
    $addHandler(extender.get_element(), "click", extender._clickHandler);
}
于 2013-07-02T20:59:23.080 回答
1

这是个好问题。由于参考说TargetControlID是必需的,我唯一会尝试的是动态创建BalloonPopupExtender控件。我可能会放一个PlaceHolder那里以确保有一个容易添加的地方。

不过,您需要一个要处理的事件来动态创建 Extender。但是您提到您想控制何时显示它。

于 2013-07-02T20:36:50.697 回答
0

谢谢你的回答,我很感激。

我找到了一种更简单的方法,最终将代码更改如下,以允许控制气球外观:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TestPage.aspx.cs" Inherits="d.TestPage" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Test Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <div>
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

        <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

        <asp:Panel ID="Panel1" runat="server">
            Balloon Information1

            <ajaxToolkit:BalloonPopupExtender ID="BalloonPopupExtender1" runat="server" BalloonPopupControlID="Panel1" TargetControlID="Label1" 
                DisplayOnClick="False" DisplayOnFocus="False" DisplayOnMouseOver="False"></ajaxToolkit:BalloonPopupExtender>

        </asp:Panel>

    </div>
    </form>
</body>
</html>

这是背后的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace d
{
    public partial class TestPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            Panel1.Visible = !Panel1.Visible;

            //BalloonPopupExtender1.DisplayOnClick = false;
        }

    }
}
于 2013-07-02T22:10:04.173 回答