473,662 Members | 2,546 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Keeping added subcontrols through postbacks

Hi,

I'm using ASP.Net 2.0 Beta 2.

I have an asp:panel that works as a list. I have a button that adds an
item to that list. When i click on the button I want a new item
(UserControl ASCX) to be added to the list.

But every time i click on the button it seems my list is cleared and
only the newest item is added to the list.

The idea is to start with an empty list and then the user can choose
among several types (ascx) through a normal dropdown and add them to
the list by clicking the "Add" button, but somehow i cannot get my
PanelControl to hold the other controls already added by previous
clicks on the add button.

ASPX:
<form id="form1" runat="server">
<asp:Button runat="server" ID="btn_Add" Text="Add"
OnClick="btn_Ad d_Click" />
<asp:Panel ID="pnl_ItemLis t" runat="server" Height="300px"
Width="400px" style="overflow-y: auto;" />
</form>

CS:

protected void btn_Add_Click( object sender, EventArgs e )
{
UserControl item = (UserControl) LoadControl( "Item.ascx" );
pnl_ItemList.Co ntrols.Add( item );
}

I think i need to do some Viewstate stuff, but the new ASP.Net 2.0
eludes me. It seems like a lot of stuff is hidden (like the
eventhandler setup).

Please let me know if you have an idea.

Thanx in advance.
JanD

Nov 19 '05 #1
2 1004
This is the same behaviour you'd get in 1.1...dynamical ly added controls
need to be re-added on each postback. They aren't preserved in viewstate
(controls are never preservered in viewstate, only control values).

Denis Bauer has a DynamicPlaceHol der control available for free that takes
care of re-recreating controls for you. not sure if it works in 2.0...
http://www.denisbauer.com/ASPNETCont...aceholder.aspx

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
<ja*****@gmail. com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Hi,

I'm using ASP.Net 2.0 Beta 2.

I have an asp:panel that works as a list. I have a button that adds an
item to that list. When i click on the button I want a new item
(UserControl ASCX) to be added to the list.

But every time i click on the button it seems my list is cleared and
only the newest item is added to the list.

The idea is to start with an empty list and then the user can choose
among several types (ascx) through a normal dropdown and add them to
the list by clicking the "Add" button, but somehow i cannot get my
PanelControl to hold the other controls already added by previous
clicks on the add button.

ASPX:
<form id="form1" runat="server">
<asp:Button runat="server" ID="btn_Add" Text="Add"
OnClick="btn_Ad d_Click" />
<asp:Panel ID="pnl_ItemLis t" runat="server" Height="300px"
Width="400px" style="overflow-y: auto;" />
</form>

CS:

protected void btn_Add_Click( object sender, EventArgs e )
{
UserControl item = (UserControl) LoadControl( "Item.ascx" );
pnl_ItemList.Co ntrols.Add( item );
}

I think i need to do some Viewstate stuff, but the new ASP.Net 2.0
eludes me. It seems like a lot of stuff is hidden (like the
eventhandler setup).

Please let me know if you have an idea.

Thanx in advance.
JanD

Nov 19 '05 #2
Thx Karl,

Yeah, it's just me being stupid. I saw the behavior that i needed in
the framework, but after a while (slow today) i noticed that it worked
on values, not controls. I've written my own little Viewstate thingy
that recreates the behavior for my controls. Thx for you reply though
:-)

-JanD

Nov 19 '05 #3

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

Similar topics

7
12497
by: Martin Schulze | last post by:
Hello, i tried to compose myself a custom usercontrol which is derieved from System.Windows.Forms.UserControl. It contains 2 comboboxes and one textbox (which are also custom controls, but directly derived from the .net classes ComboBox and TextBox) I did the custom control in the visual studio .net designer in which i
6
1952
by: foldface | last post by:
Hi If I add a UserControl to a placeholder on a page during that pages PreRender stage and press a button on that UserControl will the postback for that button get processed? I would have thought yes because on adding the control I would have thought that the OnInit, IPostBackDataHandler, etc calls would then be applied purely to that calendar, however it doesn't seem to be happening I'm getting around this at the moment by adding the...
2
2020
by: Mark | last post by:
I'm adding several controls (labels, etc.) to a placeholder programatically. I'd like the PlaceHolder to maintain these contents during postbacks without having to programmatically recreate their contents. Is there a way to do this? Thanks in advance. Mark
2
1048
by: Dimitris Pantazopoulos | last post by:
Ok, let's say I recreate the dynamically-added Dropdownlist controls of my web form even at postbacks. That means they are repopulated with values as well. (If I don't I won't be getting anything back, right?) So, how do I maintain the selectedItem between postbacks? dimitris
1
2291
by: Alan Silver | last post by:
Hello, I have a page in which I'm trying to give the user the chance to manipulate a list of items. These are the price variations for a product, so each item consists of a name (eg, small, medium, large), a price, a checkbox to say whether or not the variation is on special offer and a special price. I can pull the values out of the database OK and display them in a repeater. What I want to do is have a set of controls below the...
7
2589
by: David Lozzi | last post by:
Howdy, I have a usercontrol in my aspx page and when the page loads, I send it some property values based on the data displayed. I am sending it to a public property like below. However the usercontrol has some functions and when the function is run, I lose all of the property values. If I assign the property value to a text box, the information is not lost in the text box. I think this is by design, but how do I get around it??? ...
5
3725
by: Dennis Fazekas | last post by:
Greetings, I am creating a web form which will all the user to add an unlimited number of email addresses. Basically I have 3 buttons, "Add Another Email", "-" to remove, and a "Save" button. When the user clicks the "Add another email" it will call a client side JavaScript function, add_email, which will dynamically add a new set of controls to the webpage using the innerHTML method. It appears to work perfectly fine in the browser. The...
0
1439
by: Rune Jacobsen | last post by:
Hi all, In my project I have a control (described in an earlier post) which basically consists of three "subcontrols": One big area where the vital data is displayed (scrollable, since it will usually be larger than the window containing the parent control), a time strip on top of it, and a resource list on the left. Long story short - when someone scrolls the scrollable data control, the time strip and resource lists are hooked to keep...
7
2133
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows CType(Me.FindControl("admin" & CStr(section("buttontext")).Replace(" ", "")), adminsection2).RefreshSection() Next End Sub
0
8857
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...
0
8764
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8546
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
7367
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
6186
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
5654
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4180
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...
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1752
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.