dynamic add control

P

Peter

Hi all
The following code only work for the first click, if i click the
image button second time, it doesn't add a control dynamically. How to fix?


Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Session("numberOfUploadField") = Session("numberOfUploadField") + 1
Dim fileUpload As New FileUpload()
fileUpload.ID = "fileUpload" & Session("numberOfUploadField")
uploadPanel.Controls.Add(fileUpload)
End Sub


thanks
from Peter ([email protected])
 
P

peter

I guess it does add another control but you lose the first one between the
postbacks. If you need dynamically added controls to survive postbacks, you
need to add them in Page.Init or PreInit event.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net

Peter said:
Hi all
The following code only work for the first click, if i click the
image button second time, it doesn't add a control dynamically. How to
fix?
Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
Session("numberOfUploadField") = Session("numberOfUploadField") + 1
Dim fileUpload As New FileUpload()
fileUpload.ID = "fileUpload" & Session("numberOfUploadField")
uploadPanel.Controls.Add(fileUpload)
End Sub

you are right, i need to recreate every control in the page_load
thanks
from Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top