Persisting dynamic controls

  • Thread starter Thread starter Assaf
  • Start date Start date
A

Assaf

Hi all,

My web form creates & displays dynamic controls when a user clicks a button
(code below). No problem. But how do I persist a new control? Every postback
destroys the object never to be seen again.

Dim MyNewImageButton as New System.Web.UI.WebControls.ImageButton
:
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button3.Click
myNewButton.ImageURL = "http://...../someimage.jpg"
Me.FindControl("Form1").Controls.Add(myNewImageButton)
End Sub

Any pointers?

Thanks.

- Assaf
 
Inherently, it will be destroyed as "Page" processing completes after the
page is loaded.
You can simulate a "perceived" persistence by keeping the control's property
with a server-side "flag" value that indicates that it should be persisted
at the point specified and basically regenerate the control at each postback
based on this flag value (regenerate if "persists" else do nothing kinda
deal).

Hope this helps.
/js.
 
You need to recreate all the dynamic controls every time you make a
post back. Put the dynamic control creation into a seperate rotine and
call it in init function.
 
Back
Top