dynamic add control

  • Thread starter Thread starter Peter
  • Start date Start date
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])
 
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
 
Back
Top