suchandsuch
asked on
Create Multiple ModalPopupExtenders Dynamically in C#
Hello,
I am trying to create multiple buttons and associated modalpopupextenders, dynamically. When I create only one button and one modalpopupextender, the popup works. But when I try to create more than one button and more than one modalpopupextender, the buttons and popups don't work.
I'd very much appreciate any insights. The code is below and can be tested just by pasting it into a new .aspx file. To test the creation of multiple versus single sets of buttons and associated modalpopupextenders, just change the value of "numberOfButtonsAndModalPo pups" on line 7 below.
This code will work for " numberOfButtonsAndModalPop ups = 1 ", but not for 2, 3, 4 or more...
Thanks in advance for any help!
I am trying to create multiple buttons and associated modalpopupextenders, dynamically. When I create only one button and one modalpopupextender, the popup works. But when I try to create more than one button and more than one modalpopupextender, the buttons and popups don't work.
I'd very much appreciate any insights. The code is below and can be tested just by pasting it into a new .aspx file. To test the creation of multiple versus single sets of buttons and associated modalpopupextenders, just change the value of "numberOfButtonsAndModalPo
This code will work for " numberOfButtonsAndModalPop
Thanks in advance for any help!
<%@ Page Language="C#" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
int numberOfButtonsAndModalPopups = 1;
for (int i = 1; i <= numberOfButtonsAndModalPopups; i++)
{
Button btnNew = new Button();
btnNew.ID = "BtnPopup" + i.ToString();
btnNew.Text = "Click Me to Show PopUp Number " + i.ToString();
AjaxControlToolkit.ModalPopupExtender modalPop = new AjaxControlToolkit.ModalPopupExtender();
modalPop.ID = "MpePopUp" + i.ToString();
modalPop.PopupControlID = "ModalPanel";
modalPop.TargetControlID = "BtnPopup" + i.ToString();
modalPop.DropShadow = true;
modalPop.CancelControlID = "btnCancel";
this.Panel1.Controls.Add(modalPop);
this.Panel1.Controls.Add(btnNew);
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Panel ID="Panel1" runat="server"></asp:Panel>
<asp:Panel ID="ModalPanel" runat="server" Style="display: none" BackColor="Gray">
Dynamic ModalPopup!
<asp:Button ID="btnCancel" runat="server" Text="Close Me" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER