Dynamic custom control on custom control - events not firing

What I'm trying to do is create a module for use within a larger page.  The page itself is an order form, which will have typical payment info (address, credit card, etc.), and the ability to select what you are paying for.  Our clients will have several options in how they want the page setup.  They can either have a single form, or they can have each module on it's own page.  They can also have all the selected items fire in a single transaction, or have a seperate transaction for each item selected.  And they can limit the total number of transactions a person can make.

So what I have done is I've created the item control, containing the method for selecting a single item.  I also have the Items control, which is where I have the option to add additional items to the order.  When the purchaser adds a new item, a new item control is dynamically added to the items control.  And then the Items control is placed on the page itself.

What I have found is that the items control works fine.  It will add the individual items as it should.  The problem is that the individual item controls don't fire any events.  They will fire postbacks properly, but none of the code on the item subcontrols will run.  It's not that the events aren't being tied properly.  It's that they're just ignored.  If I turn the items control to a page, then they work fine.

3/30/2007 4:25:11 PM
asp.net.custom-server-controls 3498 articles. 0 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 39

In order for events to work on dynamically created controls, you should make sure:

1) that the controls are created dynamically before AND after the postback

2) that they are created with exactly the same ID's before and after the postback. This can go wrong if other controls are inserted after the postback.

You can check this by setting Trace=True in the page directive, and by checking the control tree in the trace output.


4/1/2007 6:38:09 PM

Thanks, that's a useful tool.  They are showing up with the same ID's each time.  I'm adding the control to an array list whenever I add it, saving the list to the session, and restoring the controls from the list on the postbacks.  Since the containter control is static, and the controls saved in the array would be saved with the id, the names shouldn't be the issue.

The trace did show a something interesting.  It is seeing something when I push the button.  The control that had the button pressed shows up under the Form Collection with an extra Name/Value pair, corresponding to the button pressed.

I've tried inheriting INamingContainer on the container control, and adding the subcontrols back to the container control in it's override for CreateChildControls, which are a couple things I've found in other threads.  So far, that hasn't helped.

One other strange thing, I put breakpoints in every method in both the page, and the two controls.  I also put in dummy code on the subcontrol's Page_Load code, so I could see if it was at least getting there.  When I am first creating the control (either automatically in the case of the first one, or on the button press) it is firing the Page_Load for that new subcontrol.  When it is recreating the subcontrols on the postback, none of them fire their Page_Load events.  I would think that's backwards, since the CreateChildControls occurs much earlier than the BTN_AddControl event.

4/2/2007 4:23:52 PM

Similar Artilces:

Custom Server Control Made of Custom Controls?
I'm giving myself a crash course in custom server controls, and I have a quick general question. Can I have a custom server control that is composed of other server controls I created. I'm pretty sure the answer is yes, but I want to be positive. Yes http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpcondevelopingcompositecontrols.asp Shows how to combine existing controls into a new control using class composition. -ron Thanks! ASP.NET so rocks! Making page components extensible objects is such a great idea! I love it....

Usercontrol vs Custom Server Controls, Any need for Custom Server Controls
Hello I'm new to ASP.Net so this is probably a stupid question but, is there any need to create customer server controls now that you can pre-compile usercontrols into a dll and thus easily share between applications? This blog post from David Ebb describes how to do it and the restrictions he note don't seem that bad (other than being able to embed resources such as images in the dll). http://blogs.msdn.com/davidebb/archive/2005/10/30/487160.aspx His article desribes the techniques for ASP.Net 2.0 and he suggests that there will be further improvements in .Net 3.5 in this ar...

Custom Server Control Vs Web Parts, Any need for Custom Server Control
Hello I've just posted a similar question on why you need server controls when you can pre-compile usercontrols and redistribute them. http://forums.asp.net/p/1397433/3010100.aspx#3010100 I've seen lots of (usercontrol vs web part) but not much on web part vs custom server control. According to the MSDN site you can put web parts onto a normal asp.net page outside of a web part zone and they behave just like custom server controls. So, if you are creating a bunch of controls for redistribution to customer asp.net sites and/or SharePoint sites why don't you just create Web Par...

Custom Control within a Custom Control
I have two individual custom controls say custom cc1 and cc2. cc1 is communicating to cc2 using event delegate mechanism.I have tested the behaviour by dropping cc1 and cc2 onto a Web Page and it works fine. I want to create a third custom control say cc3 which should contain both cc1 and cc2. So that if i drag and drop cc3 onto a Web Page i can acheive exactly what i am doing above. The problem is that i am not sure how to call/register a custom control within a custom control ? Any clue ? Thanks!! Hi, Do you mean adding custom control to custom control? I think you can use the same wa...

how to have both server controls and html controls rendered in a custom control?
I have a custom control in which there is an html text box.when you click on it , a div containing a table is appeared and according to what you select in that table a text is set to the text box. It works fine but the problem is: as the text box is an html element it doesn't have viewstate and when a post back occures in the page its value disappeares.I tried a hidden field to keep its value.again there is another problem : I put this custom control in a usercontrol and put the usercontrol in a multiview and by clicking on a button this view is selected and by clicking another bu...

Custom Control within a Control Control
I am developing a custom controls that will render headers for different web sites. Within these controls, I want to place another custom control that will change the language. I created the language control and had it implement IPostBackDataHandler. This control works fine if I drag it on a new web form, but if I tell a header custom control to render it problems occur. The Language Selector custom control does not have a Page member anymore and the event handlers do not work. Does anyone have any experience with doing something similiar? Anyone have any suggestions? Thanks, ...

Creating Custom Controls With Custom Controls Inside Of Them
Hello, I am trying to create a custom control for creating tabs. The idea is that our designer can just use the control tags to generate the tabs.  The problem that I am running into is that I want to be able to have a custom control that allows any number of child custom controls. So there would be a TabContainer Control, and within that there would be any number of tabs.  The idea is similar to how an asp:DropDown list can have any number of ListItems within them.  Here is my code, any help is appreciated. 1 <!-- TAB CONTAINER -->2 <%@ Control Language=&...

Custom controls called from inside other custom controls???
I'm fairly new to writing controls in ASP.NET so, forgive the I am trying to create a base page class which will call 3 custom controls. This base page class will span across multiple projects hence the reason I am not creating user controls. These 3 custom controls are: 1. TopNav-uses render method to display an HTML table with graphics for top navigation. 2. ImagePairs-uses prerender method to add javascript code to manage what graphic is displayed in TopNav onMouseOver and onMouseOut 3. MgrHeader-uses render method to display an HTML table with s...

Custom User Controls v. Custom Web Controls
Hi! Is it better for me to begin coding my controls instead of just designing them? What would the benefits be? I meen, i seem to be able to get all i need from just putting stuff together on an ASCX file but i'm obviously missing a huge concept here... please explain! Hi, creating user controls is indeed easier than creating custom server controls because you can simply drag & drop other controls on the form, easily add events to it, ... Custom controls however are better when you want to reuse them in several other projects. I like to create custom controls for small, reusable com...

Web Custom Control within a Web Custom Control
I was wondering if this can be done and how. I've created a simple custom control that displays a header which is my first custom control. So I'm just a baby when it comes to this.. Within the header I currently have a property for breadcrumbs which is a string. What I would like to do is have the breadcrumb property  be a Link Button List. I did find a custom control of a Link Button List which is exactly what I wanted. My question is how can/do  I include this into my custom control? Can it done? How? Please help? I'm at a lose here.   Susan You should be able to do ...

Custom Web Control inside another Custom Web Control
Hi I created a custom web control (CusWebNew) that displays some textboxes by adding them to the ControlCollection of the webcontrol. I also created a custom webcontrol (CustWebButton) that inherts from Button control, and overrided the OnClick function. When I use CustWebButton on a regular web form, it seems to function correctly. However, when I added to be part of the ControlCollection of CustWebNew, it stops to work.   Any ideas why? Thanks Hey, What do you mean by stops to work?  Explain what you are trying to do with it and what it doesn't do.Brian"Trust in the...

Custom Server Control with Child Controls
I have a custom server control <xx.Parent... /> which parses custom child controls <xx.Child... />. In Visual Studio 2008, IntelliSense shows me both when I start typing my control namespace. How can I prevent the child control from showing up in IntelliSense  unless I'm adding it within the parent tags?Thanks. --Rudy...

Custom Server Control With Child Control
All, I am currently putting together a very simple control. The new control outputs a table with two rows. The top row contains a heading and the bottom row will contain any other content. The control as it stands works perfectly well and I can place text into the content row no problem. Now, to the problem. Once I'd completed the control I figured it would be neat to enable the developer to add controls directly into the bottom row (content row) of the outputted table. As you probably know the WebControl class has a Controls collection which the developer can use to add any other...

Dynamically Loaded User Control inside Custom Server Control Weirdness
Hello, I have a wizard controller server control that walks the steps of a wizard and dynamically loads the user control to display for the wizard page using Page.LoadControl. Everything is working great! Until this showed up. One of the controls on the user control is another custom server control. This server control on the dynamically loaded user control makes use of RegisterClientScriptBlock. For some reason, the client side code for RegisterClientScriptBlock never gets rendered! I stepped through the code to ensure that RegisterClientScriptBlock gets called, it does. If I ...

Why can't I add controls dynamically to my customer server control?
This is a simple example of a custom control where I dynamically add a new control to the hierarchy. The problem is when I click the 'C' button, it adds the B button and then the next click of the 'C' button will hit the B_Click event handler. My only theory is that since it was added to the middle of the control heirarchy, then event handling got confused. Has anyone seen this problem or am I doing something wrong? using System; using System.Configuration; using System.Collections; using System.Text.RegularExpressions; using System.Xml; using System.Data; using S...

Web resources about - Dynamic custom control on custom control - events not firing - asp.net.custom-server-controls

Dynamics - Wikipedia, the free encyclopedia
Brownian dynamics , the occurrence of Langevin dynamics in the motion of particles in solution (e.g. a grain in water, as was first seen by Brown); ...

Datacenter Dynamics
Datacenterdynamics for data center information, conferences, news, videos, whitepapers and reports globally

Dynamic Chiropractic - chiropractic, news, articles, research & information for chiropractors - Find ...
Dynamic Chiropractic - chiropractic, news, articles, research & information for chiropractors - Find a Chiropractor

Paul Melville: a dynamic talent taken before his time
What might have become of a popular young cricketer with the world at his feet?

Lenovo and Apple: PCs’ Dynamic Duo, Gobbling Up Share in Downbeat Market
... in units sold, with gains in market share for top vendor Lenovo Group ( 0992HK ), and for Apple ( AAPL ), who turned out to be the Dynamic Duo ...

Seattle Councilmember O'Brien: Power dynamic between Uber, drivers is out of balance
Seattle is the first city in the U.S. to give Uber drivers the right to form a union, but whether that actually happens might be up to the courts. ...

SNL perfectly captured the dynamics of the Republican presidential race
The "Saturday Night Live" recap of the latest Republican presidential debate reflected fairly accurately the state of the GOP primary. Beck ...

Rise of the Tomb Raider director leaves Crystal Dynamics for Infinity Ward
Tomb Raider Senior Art Director and Rise of the Tomb Raider Game Director Brian Horton has left Crystal Dynamics, the developer announced via ...

The story behind Master & Dynamic's mix of sound and design
Master &amp; Dynamic's latest headphones, the wireless over-ear MW60s, may have been announced ahead of CES, but that didn't stop me from getting ...

Are Boston Dynamics' Robot Reindeer The Ghosts Of Christmas Future?
Either that, or the nightmare before Christmas. The Google-owned robotics company Boston Dynamics delivered a unique holiday greeting this week: ...

Resources last updated: 1/16/2016 6:29:02 PM