Dear,
Thats interesting. But the logic you have is a bit tedious. You are doing that in code behind. Why dont you do that in javscript?? You can do the same in script.
Any way, since you are using update panel, adding new controls to page controls is incorrect. UpdatePanel will update its content only, not the whole page. So Add a place holder to ContentTemplate then add your controls to that place holder...
I ve written a sample. Used a place holder "phFeedback", and adding to it. Refer this
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public static class FeedBack
{
public static void ShowDialog(string msg)
{
Page page = HttpContext.Current.CurrentHandler as Page;
Panel panel = new Panel();
panel.ID = "panelError";
panel.CssClass = "errorDialog";
Label labelMsg = new Label();
panel.Controls.Add(labelMsg);
msg += "<br/><br/>Please describe what you were doing when this occurred:<br/>";
labelMsg.Text = msg;
TextBox textBox = new TextBox();
textBox.ID = "textBoxFeedback";
textBox.Style.Add("width", "95%");
textBox.Style.Add("background-color", "#ffff40");
textBox.Height = 40;
panel.Controls.Add(textBox);
Button button = new Button();
button.Text = "OK";
button.Width = 50;
button.Style.Add("margin-top", "20px");
panel.Controls.Add(button);
var ph = page.GetAllControls().OfType<PlaceHolder>().Where(a => a.ID == "phFeedBack").ToList();
if(ph.Count!=0)
((PlaceHolder)ph[0]).Controls.Add(panel);
}
public static IEnumerable<Control> GetAllControls(this Control parent)
{
foreach (Control control in parent.Controls)
{
yield return control;
foreach (Control descendant in control.GetAllControls())
{
yield return descendant;
}
}
}
}
I used LINQ. If LINQ is not applicable then write a for loop and get all controls. Dont forget to add place holder to ContentTemplate of UpdataPanel... And I recommend you to use JavaScript if possible 