Ajax BalloonPopup Extender in ASP.Net

Ajax BalloonPopup Extender

The BalloonPopupExtender control is used to display a popup that can contain any content. Here we will see an example to display help information or we can say a message when we move the focus to a TextBox control.
 
BalloonPopupExtender Properties
 
  • TargetControlID: It is used to set the ID of the TextBox control we want to display the Balloon Popup for.

  • BalloonPopupControlID: It is used to set the ID of the Panel Control that will contain the Content to be displayed as a Balloon Popup.

  • Position: This property sets the display position of the Balloon Popup. Like Auto, BottomRight, BottomLeft, TopRight and TopLeft.

  • UseShadow: This property adds a Shadow effect to the Balloon Popup.

  • DisplayOnFocus: When this property is set to TRUE the Balloon Popup will be displayed when the TextBox control gets the focus.

  • DisplayOnMouseOver: When this property is set to TRUE the Balloon Popup will be displayed when the mouse hovers over the TextBox control.

  • DisplayOnClick: When this property is set to TRUE the Balloon Popup will be displayed when the TextBox control is clicked.

  • BalloonStyle: This property sets the style of the Balloon Popup, two preset styles are Cloud and Rectangle,
The third style is Custom, it is used to allow us to use Custom Balloons.
 
Let's understand it with an example

Step 1: Open Visual Studio and create a project named BalloonPopupExtender.

Step 2
: Add one Webform named BalloonPopup.

Step 3
: Now in design view we will add a ToolkitScriptManager.
 
 
  1. <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">  
  2. </asp:ToolkitScriptManager>  
Step 4: Now we will add a Lable control and a BalloonPopupExtender next to the TextBox control for which we want to display the Balloon Popup. It requires a Panel control that contains its content.
 
 
 
The source code will be like this.
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BalloonPopup.aspx.cs" Inherits="BalloonPopupExtender.BalloonPopup" %>  
  2.   
  3. <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>  
  4.   
  5. <!DOCTYPE html>  
  6.   
  7. <html xmlns="http://www.w3.org/1999/xhtml">  
  8. <head runat="server">  
  9.     <title></title>  
  10. </head>  
  11. <body>  
  12.     <form id="form1" runat="server">  
  13.     <div>  
  14.       
  15.         <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">  
  16.         </asp:ToolkitScriptManager>  
  17.         <asp:Label ID="Label1" runat="server" Text="First Name"></asp:Label>  
  18.         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
  19.         <asp:BalloonPopupExtender ID="BalloonPopupExtender1" runat="server"></asp:BalloonPopupExtender>  
  20.         <asp:Panel ID="Panel1" runat="server"></asp:Panel>  
  21.      <br />  
  22.         <asp:Label ID="Label2" runat="server" Text="Last Name"></asp:Label>  
  23.         <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>  
  24.         <asp:BalloonPopupExtender ID="BalloonPopupExtender2" runat="server"></asp:BalloonPopupExtender>  
  25.         <asp:Panel ID="Panel2" runat="server"></asp:Panel>  
  26.      <br />  
  27.         <asp:Label ID="Label3" runat="server" Text="Password"></asp:Label>  
  28.         <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>  
  29.         <asp:BalloonPopupExtender ID="BalloonPopupExtender3" runat="server"></asp:BalloonPopupExtender>  
  30.         <asp:Panel ID="Panel3" runat="server"></asp:Panel>  
  31.       
  32.     </div>  
  33.     </form>  
  34. </body>  
  35. </html>  
Now the Design view will be like this.
 
 
 
Step 5: Now we will provide some properties for the BalloonPopupExtender by which we will get the desired output. Here we will use the image "key.png" inside the panel control so we need to put this image inside the images folder.
 
 
The source code will be as follows:  
  1. <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="BalloonPopup.aspx.cs" Inherits="BalloonPopupExtender.BalloonPopup" %>  
  2.   
  3. <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>  
  4.   
  5. <!DOCTYPE html>  
  6.   
  7. <html xmlns="http://www.w3.org/1999/xhtml">  
  8. <head runat="server">  
  9.     <title></title>  
  10. </head>  
  11. <body>  
  12.     <form id="form1" runat="server">  
  13.     <div>  
  14.       
  15.         <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">  
  16.         </asp:ToolkitScriptManager>  
  17.   
  18.         <asp:Label ID="Label1" runat="server" Text="First Name"></asp:Label>  
  19.         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
  20.         <asp:BalloonPopupExtender ID="BalloonPopupExtender1" runat="server" TargetControlID="TextBox1" BalloonPopupControlID="panel1" BalloonStyle="Cloud"  
  21.             DisplayOnFocus="true" Position="BottomRight" UseShadow="true">  
  22.         </asp:BalloonPopupExtender>  
  23.         <asp:Panel ID="Panel1" runat="server">  
  24.              <img src="Images/key.png"/>Please enter First Name</asp:Panel>  
  25.      <br />  
  26.      <br />  
  27.         <asp:Label ID="Label2" runat="server" Text="Last Name"></asp:Label>  
  28.         <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>  
  29.         <asp:BalloonPopupExtender ID="BalloonPopupExtender2" runat="server" TargetControlID="TextBox2" BalloonPopupControlID="panel2" BalloonStyle="Rectangle"  
  30.             DisplayOnFocus="true" Position="BottomRight" UseShadow="true" >  
  31.        </asp:BalloonPopupExtender>  
  32.         <asp:Panel ID="Panel2" runat="server">  
  33.              <img src="Images/key.png"/>Please enter Last Name</asp:Panel>  
  34.      <br />  
  35.      <br />  
  36.         <asp:Label ID="Label3" runat="server" Text="Password"></asp:Label>  
  37.         <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>  
  38.         <asp:BalloonPopupExtender ID="BalloonPopupExtender3" runat="server" TargetControlID="TextBox3" BalloonPopupControlID="panel3" BalloonStyle="Cloud"  
  39.             DisplayOnFocus="true" Position="BottomRight" UseShadow="true">  
  40.         </asp:BalloonPopupExtender>  
  41.         <asp:Panel ID="Panel3" runat="server">  
  42.            <img src="Images/key.png"/>Password must be 5 to 10 char</asp:Panel>  
  43.       
  44.     </div>  
  45.     </form>  
  46. </body>  
  47. </html>                                         
Now the design view will be like this.
 
 
Step 6: Now run the project and see the output.
 
 
 
 
 
 
 
This is all about the AJAX BalloonPopup Extender and how to use it in ASP.NET.

Thank you and happy coding.


Similar Articles