ASP.NET - How to call BalloonPopupExtender on dropdown SelectedIndexChanged event

Asked By Venkatesh Desai on 17-Oct-13 05:33 AM
Hi All,

How to call BalloonPopupExtender on dropdown SelectedIndexChanged event on code behind

i have a sample code please have a look on that,


<asp:DropDownList runat="server" ID="ddlPollutant" Width="130px" AutoPostBack="true" OnSelectedIndexChanged="ddlPollutant_SelectedIndexChanged">
     <asp:ListItem Text="--Select--" Value="-1" Selected="True"></asp:ListItem>
     <asp:ListItem Text="H2S" Value="34.08"></asp:ListItem>
     <asp:ListItem Text="SO2" Value="64.0628"></asp:ListItem>
     <asp:ListItem Text="HCl" Value="36.461"></asp:ListItem>
     <asp:ListItem Text="NH3" Value="17.0306"></asp:ListItem>
     <asp:ListItem Text="HCN" Value="27.0253"></asp:ListItem>
     </asp:DropDownList>
<asp:Panel runat="server" ID="Panel1" Style="display: none">
    <table cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td nowrap="nowrap">
      NaOH at low pH
      </td>
    </tr>
    <tr>
      <td nowrap="nowrap">
     NaOH at high pH
      </td>
    </tr>
    </table>
 </asp:Panel>

protected void ddlPollutant_SelectedIndexChanged(object sender, EventArgs e)
    {
    if (ddlPollutant.SelectedItem.Text == "H2S")
    {
    BalloonPopupExtender BPE = new BalloonPopupExtender();
    BPE.TargetControlID = ddlPollutant.ID;
    BPE.BalloonPopupControlID = Panel1.ID;
    BPE.Position = BalloonPopupPosition.BottomRight;
    BPE.BalloonStyle = BalloonPopupStyle.Rectangle;
    BPE.BalloonSize = BalloonPopupSize.Medium;
    BPE.UseShadow = true;
    BPE.DisplayOnMouseOver = true;
    BPE.DisplayOnClick = false;
    BPE.DisplayOnFocus = false;
    Panel1.Attributes.Add("style", "display:block");
    }
    if (ddlPollutant.SelectedItem.Text == "SO2")
    {
    Panel1.Attributes.Add("style", "display:none");
    }
    if (ddlPollutant.SelectedItem.Text == "HCl")
    {
    Panel1.Attributes.Add("style", "display:none");
    }
    if (ddlPollutant.SelectedItem.Text == "NH3")
    {
    Panel1.Attributes.Add("style", "display:none");
    }
    if (ddlPollutant.SelectedItem.Text == "HCN")
    {
   Panel1.Attributes.Add("style", "display:none");
    }
    }

But it was not working for me .

Please give solution to this.

Thanks in advance,
VenkiDesai.
Robbe Morris replied to Venkatesh Desai on 17-Oct-13 10:06 AM
I see where you create the instance of the control but I don't see where you attach it to a Panel or to the page.  Typically, server side controls need to be attached to the page in the Page_Init section.  I admin, I don't use this control.  But, I think the correct way to implement this is to put it in the ASPX portion of your page and set visible = false.  On postback of your dropdownlist, you'd make it visible and set the various desired properties.