473,714 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 MyNewImageButto n as New System.Web.UI.W ebControls.Imag eButton
:
Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
myNewButton.Ima geURL = "http://...../someimage.jpg"
Me.FindControl( "Form1").Contro ls.Add(myNewIma geButton)
End Sub

Any pointers?

Thanks.

- Assaf

Nov 18 '05 #1
2 1648
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%******** ********@TK2MSF TNGP12.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 MyNewImageButto n as New System.Web.UI.W ebControls.Imag eButton
:
Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
myNewButton.Ima geURL = "http://...../someimage.jpg"
Me.FindControl( "Form1").Contro ls.Add(myNewIma geButton)
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#******* *******@TK2MSFT NGP12.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 MyNewImageButto n as New System.Web.UI.W ebControls.Imag eButton
:
Private Sub Button3_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button3.Click
myNewButton.Ima geURL = "http://...../someimage.jpg"
Me.FindControl( "Form1").Contro ls.Add(myNewIma geButton)
End Sub

Any pointers?

Thanks.

- Assaf

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
1824
by: John Smith Jr. | last post by:
I am looking for some way to persist a table web control so when page_load event comes up, i can display the table as it was. I tried using ViewState with the rows collection but that didn't work to well as I got an error trying to put rows collection in the viewstate. My problem is this: I load a table with rows and controls, then wire events, this is after clearing the rows of the table initially in this function.
3
2269
by: Stu | last post by:
Hi, I am creating a control in a PlaceHolder like so: Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click Dim ctrl As AcceptOrCancel = CType(Page.LoadControl("controls/AcceptOrCancel.ascx"), AcceptOrCancel) PlaceHolder1.Controls.Add(ctrl)
5
4837
by: Dick | last post by:
I have a GridView bound to an ObjectDataSource. I have a Button that calls GridView.DataBind. I want the row that is selected before the DataBind to still be selected afterwards. This happens automatically if the data doesn't change. But if records have been added or deleted then it looks as if some code is necessary: I've done this by using GridView.SelectedValue to get the key value of the currently selected Row and then by itterating...
1
441
by: dougloj | last post by:
Hi, In my ASP.NET application, I want to be able to dynamically create RadioButtonLists and/or CheckBoxLists according to what is in my database. I wrote routines to create RadioButtonLists and CheckBoxLists. Each routine pulls data out of my database, populates the respective control, and passes the control back to the caller. The caller places the returned controls into a table. The controls are displayed as expected.
0
9307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9009
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7946
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6627
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4462
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2105
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.