Question

I have this script in ASP.NET/C# - I trying to control when to show the balloon popup and as preliminary test I specifically instruct the popup extender not to show at any condition.

But it still shows on click..

How to tell the BalloonPopupExtender to disable itself and not to show at all?

(Later on I would like to enable it again to show - but that information is just to give a completion to why do I want it there in the first place..)

<!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>
Was it helpful?

Solution 3

Thank you for the answers, I appreciate it.

I found an easier way and ended up altering the code as follows to allow control of balloon appearance:

<%@ 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>

And this is the code behind:

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;
        }

    }
}

OTHER TIPS

That's a good question. Since the reference says the TargetControlID is required, the only thing I would try is dynamically creating the BalloonPopupExtender control. I'd probably put a PlaceHolder there to make sure there's an easy place to add it.

You'd need an event you want to handle to dynamically create the Extender, though. But you mentioned that you want to control when to show it.

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);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top