469,927 Members | 1,267 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

Persisting dynamic controls

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(myNewImageBut ton)
End Sub

Any pointers?

Thanks.

- Assaf

Nov 18 '05 #1
2 1500
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.

"Assaf" <at@isp.com> wrote in message
news:u%****************@TK2MSFTNGP12.phx.gbl...
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(myNewImageBut ton)
End Sub

Any pointers?

Thanks.

- Assaf

Nov 18 '05 #2
Ram
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.

"Assaf" <at@isp.com> wrote in message news:<u#**************@TK2MSFTNGP12.phx.gbl>...
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(myNewImageBut ton)
End Sub

Any pointers?

Thanks.

- Assaf

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by John Smith Jr. | last post: by
1 post views Thread by dougloj | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.