Hi Gayathri79,
I found out what the problem is. You were close, but you need to make four changes to make this work.
First, you need to use UniqueID (used for postback scenarios) instead of ClientID (for client script):
Code:
hov.TargetControlID = but1.UniqueID;
Secondly, the ID of the button is not valid as it contains a space. Change this:
Code:
but1.ID = "Button " + i.ToString();
to this:
Code:
but1.ID = "Button" + i.ToString();
Next, you need to enable the line that adds the Panel to the Form or there won't be a panel to show by the hover extender.
Code:
Form.Controls.Add(pan10);
Finally, the order of your code is important. Consider your current code:
Code:
hov.TargetControlID = but1.ClientID;
hov.PopupControlID = pan10.ClientID;
Form.Controls.Add(hov);
Table1.Rows.Add(firstrow);
The first line assigns the ClientID (which should be UniqueID) of the button to the TargetControlID. However, at this stage, the button doesn't know it's inside a table that's inside a Master Page. So, at this stage, it simply returns Button0 for the first button. However, once all controls are added to the form (by adding firstrow to the table), the control hierarchy is known and the UniqueID of the button is changed from Button0 to ctl00$MainContentholder$Button0 which is the ID that the hover panel needs.
So, simply assigning the UniqueID of the button to the extender *after* all controls are added to the form should do the trick:
Code:
AjaxControlToolkit.HoverMenuExtender hov = new AjaxControlToolkit.HoverMenuExtender();
hov.PopupControlID = pan10.ClientID;
Form.Controls.Add(hov);
Table1.Rows.Add(firstrow);
hov.TargetControlID = but1.UniqueID;
This way, TargetControlID gets assigned the full unique ID of the button control.
For your reference, here's the complete working code:
Code:
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i <= 10; i++)
{
TableRow firstrow = new TableRow();
TableCell firstcell = new TableCell();
Button but1 = new Button();
but1.ID = "Button" + i.ToString();
but1.Text = but1.ID;
firstcell.Controls.Add(but1);
firstrow.Cells.Add(firstcell);
Panel pan10 = new Panel();
pan10.Height = Unit.Pixel(100);
pan10.Width = Unit.Pixel(100);
pan10.BackColor = Color.Chocolate;
pan10.ID = "panel" + i.ToString();
Label lab = new Label();
lab.ID = "label" + i.ToString();
lab.Text = "This Panel contains Button Client Id: " + but1.ClientID;
pan10.Controls.Add(lab);
Form.Controls.Add(pan10);
AjaxControlToolkit.HoverMenuExtender hov = new AjaxControlToolkit.HoverMenuExtender();
hov.PopupControlID = pan10.ClientID;
Form.Controls.Add(hov);
Table1.Rows.Add(firstrow);
hov.TargetControlID = but1.UniqueID;
}
}
Hope this helps,
Imar