Tags: adding, ajax, asp, aspnet, container, control, controls, dynamically, net, page, panel, runtime, updatepanel, vs2005, web
Adding a control to an UpdatePanel at runtime
On .Net » ASP.NET AJAX
3,647 words with 4 Comments; publish: Sun, 06 Jan 2008 08:43:00 GMT; (10092.77, « »)
Hi all,
I have a web page (asp.net 2.0, vs2005) in which I add controls dynamically to a Panel control.
Now I changed the container in an UpdatePanel.
Usually I simply add a newly created control with a statement like this:
PanelContainer.Controls.Add(MyNewControl)
With UpdatePanel do I need to do anything else ?
I asked because my control doesn't get updated correctly.
I tried adding a line
ScriptManager1.RegisterAsyncPostBackControl(MyNewControl);
but with no sucess..
Does anyone have any tips/suggestions/advices ?
Thanks in advance
Bye
Nicola
http://net-ajax.itags.org/q_dotnet-ajax_14176.html
All Comments
Leave a comment...
- 4 Comments

- Try out this Button btnButton =newButton();btnButton.Text="New Button";
UpdatePanel1.ContentTemplateContainer.Controls.Add(btnButton);
my page orginally has this
<
asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><asp:ButtonID="Button1"runat="server"OnClick="Button1_Click"Text="Button"/></ContentTemplate></asp:UpdatePanel>#1; Sun, 06 Jan 2008 08:45:00 GMT

I tried but it doesn't work (thanks anyway for answering!)
To clarify my problem: in the page_load I write the text inside the dynamically added control.
Something like this:
Textbox MyT = new Textbox();
MyT.Text = "test string";
PnlContainer.Controls.Add(MyT);
In the debugger I see the new value, but it doesn't get updated in the web page.
#2; Sun, 06 Jan 2008 08:46:00 GMT

As a Final Statemet of update call this
UpdatePanel1.Update();
#3; Sun, 06 Jan 2008 08:47:00 GMT

I tried but it doesn't work neither.
I eventually find out that the problem could depend on the third-parties server controls that I am using.
Thanks anyway for answering
Bye
Nicola
#4; Sun, 06 Jan 2008 08:48:00 GMT