Hi,
I am giving an example of controls add to the popup and assign to the Modalpop up extender.
In my aspx page I am simply having
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<asp:ScriptManager runat="server" ID="script1"></asp:ScriptManager>
<asp:ModalPopupExtender ID="Panel1_ModalPopupExtender" runat="server"
DynamicServicePath="" Enabled="True" TargetControlID="Button6" >
</asp:ModalPopupExtender>
<asp:Button ID="Button6" runat="server" Text="ShowPopup" />
<asp:Panel runat="server" ID="Panel2"></asp:Panel>
</asp:Content>
The popup control, ok button, cancel button and all added and assigned at runtime from code behind.
protected void Page_Load(object sender, EventArgs e)
{
Panel Panel1 = new Panel();
Panel1.ID = "Panel1";
TextBox text1 = new TextBox();
Button button1 = new Button();
button1.Text = "OK";
Button button2 = new Button();
button2.Text = "Cancel";
Button button3 = new Button();
button3.Text = "Submit";
Panel2.Controls.Add(Panel1);
Panel1.Controls.Add(text1);
Panel1.Controls.Add(button1);
Panel1.Controls.Add(button2);
Panel2.Controls.Add(button3);
Panel1_ModalPopupExtender.PopupControlID = Panel1.ID;
Panel1_ModalPopupExtender.OkControlID = button1.ID;
Panel1_ModalPopupExtender.CancelControlID = button2.ID;
button3.Click += new EventHandler(SubmitButtonClick);
}
protected void SubmitButtonClick(object sender, EventArgs e)
{
}
These controls can be added and assigned in any event, but the popupcontrolid for the extender should be assigned on page load event.
In your case...
The dynamic button is add on a button click event. Button click event is firing after page load event. After page loaded event handler can't be assigned. So you need to have the button on page load event. Also if you assign the button to a div control which created after page load (the Div is only render, it will not be available for instantiation on post back), then the button instance will not be available on submit. So handler will not work.
You can do this way.
Have the dynamic button as a global to the form. Then in page load..
Button dynamicButton;
protected void Page_Load(object sender, EventArgs e)
{
dynamicButton = new Button();
dynamicButton.Style.Add("Visibility","Hidden");
dynamicButton.ClientIDMode = ClientIDMode.AutoID;
dynamicButton.Height = 40;
dynamicButton.Width = 200;
dynamicButton.Text = "I am Dynamic Button";
dynamicButton.Click += new EventHandler(DynamicButton_Click);
Panel2.Controls.Add(dynamicButton);
}
This panel2 has to be next to the topic_rows where you are adding the TopPaneDiv4 . So visibly it shows next to the TopPaneDiv4.
Next have your Create Dynamic function should be like ...
private void CreateDynamicButton()
{
dynamicButton.Style.Add("Visibility", "Visible");
HtmlGenericControl TopPaneDiv3 = new HtmlGenericControl("div");
TopPaneDiv3.Attributes.Add("class", "header_Level_float_rowLast2");
TopPaneDiv4.Controls.Add(TopPaneDiv3);
}
So you are not dynamically adding the button at button click. But dynamically adding it on page load and make it hide and visible as per the need.
Hope this helps.