getting postback events to fire for dynamically added custom controls

I recently posted regarding these 2 controls, but this is a completely different issue, so I thought it best to start a new thread.

I have two composite controls (neither renders content, rather they add controls to the control tree). Control X is declared on the page and is passed a custom collection. X iterates through this collection and creates a tab and a 'pane' for each item in the collection. To each pane it adds an instance of control Y, which contains a couple of textboxes and a hidden inputbox.
My problem is:
if I have a std button on the page which posts back, I need the instances of Y to keep (and update) their state. I can't get any postback events to raise on the instances of Y - they just seem to create new instances of themselves (with the same name on each form element). I'm calling the EnsureEventsHiddenInputBox method in Y's OnPreRender method.
At the moment i'm supplying Y with it's 'source' collection in the aspx Init, whether it's a postback or not. Is this part of the issue? Should I be storing the state of X (including all info about each Y) in X?
I've written a few server controls now, all of which are much more complex than this one, but I just can't get my head around this for some reason...
Any tips before I resort to hardcoding everything into the aspx?!
Thanks,
Burns
0
montyburns
4/16/2004 12:59:59 PM
asp.net.hosting-open-forum 4216 articles. 0 followers. Follow

5 Replies
659 Views

Similar Articles

[PageSpeed] 9
Get it on Google Play
Get it on Apple App Store

Haven't a clue as to understanding what you are really doing but a few things do come to mind, that may or may not make a difference. 1.)Besure to assign ID's to them durring the init creation process... I am guessing but it may affect something if the ID's are getting generated later in the processing. 2.) Are all the panels visible ? Doesn't that affect the rendering and saving of viewstate just a guess but could be an issue. It's not going to save viewstate of a control that isn't render(atleast I don't think so lol). GoodLuck
Answering a question increases your knowledge asking a question shows your Intelligence!
0
FancyKetsup
4/16/2004 1:52:26 PM
Yes, I have a tip :-) .

The trick over there in your composite control is to recreate all the controls before the end of the Load event. So you should have some code like so:

protected override void OnLoad(EventArgs e) {
EnsureChildControls(); // assuming that you build the control tree under CreateChildControls method
base.OnLoad(EventArgs e);
}

In fact, I recommend that you do that in the Init part of the life cycle; however, it all depends on how much your control knows at each stage of the life cycle.
-- Justin Lovell
0
master4eva
4/17/2004 12:35:10 PM
thanks guys, much appreciated.  I think you may both be onto something.  If I get a chance i'll try adding them in Init and see if it makes any difference.

As it happens I sort of went back to basics to solve it. As i'm creating each instance of Y I know what each form element's name/id will be (within Y), so I just assign the values from the form post (if an item exists) for each element.
It may not be a very '.Net' way of doing things, but I think it's actually better as I don't have to use viewstate, deal with postback in the control etc.
Anyway, thanks again for your help.
Burns
0
montyburns
4/20/2004 2:48:33 PM
and i've just discovered the downside to this way of doing it!  (if you set visible to false on postback, the form elements aren't written to the page [obviously...] and the control resets itself to blank values on the next postback)

Back to the drawing board...
0
montyburns
4/20/2004 4:34:44 PM
In place of making the panels visible, can you set the width to 1?  The intent is for them to be drawn on the form but not be visible.
0
vranastl
4/25/2004 12:44:23 AM
Reply:

Similar Artilces:

Button click event not getting fired for a custom webpart where controls are added dynamically.
 We are migrating from ASP.NET1.1/Sharepoint 2003 to ASP.NET 2.0/Moss 2007. We have a webpart on which controls are getting added dynamically. We have a button which is also dynamically added and a click event handler is also attached to it. However when we click on this button the page gets posted but the event is not fired. We analysed and found that the code to add the button in the webparts controls collection is executed but the code to add the button to it's container (that is a table) is not getting executed. Hence the event is not getting handled. If we forcefully add the bu...

dynamically added linkbutton control, click event firing but cannot get page to open in iframe
I have a dynamically added linkbutton control (sorry for code layout, i get a noxmlhttp error when trying to use the source code box for posting) added like so: Private Sub AddSecondLevelLinks(ByVal theTitle As String, ByVal theUrl As String) Dim lb As New LinkButtonlb.Text = theTitle lb.ID = lb.Text lb.CommandArgument = theUrl lb.Visible = True lb.CssClass = "secondLevel"Panel2.Controls.Add(lb) AddHandler lb.Click, AddressOf SecondLevelButtonClickEnd Sub When i click the button my eventhandler definitely fires (drops in here in debug) but does not work as expe...

Custom control adding user controls dynamically
I'm trying to develop a custom control in .NET 2.0 which builds a page based on an XML document.  What it should be doing is looking through an XML file to see which user controls need to be loaded and where on the page they should go.  The concept is quite simple and I had it working fine in .NET 1.1, but .NET 2.0 doesn't want to know.  Loading the XML etc is all fine, but I'm really struggling to load the controls and get all their events to fire.I'm using Page.LoadControl and .Controls.Add(...) which does the job but I can't get all the events to fire in...

Dynamic custom control on custom control
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...

Button click event not fired for a custom webpart where controls are added dynamically.
We are migrating a Sharepoint 2003 site to MOSS 2007 and ASP.NET 2.0. We have also migrated the webparts but they are still inheriting from Sharepoint.WebPart. We have a webpart where controls are added dynamically at runtime. On this webpart a button is added dynamically and a click event handler is also attached. The button on the webpart is displayed only when there is some data. The button deletes the selected row of data when clicked. But when we click on the button, the page gets posted but the event handler is not called. We analysed and found that the code where we add the button to ...

Event not firing with Dynamic Controls in a Custom Web Control
I'm creating some LinkButtons on the fly (on Load) and they show up just fine.  The problem is that the AddHandler event I created is not firing.  I'm at a loss...have read a ton of articles today, but just can't figure this one out.  Please help a newb! :-)Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) EnsureChildControls() If Me.Page.IsPostBack Then Me.Units = Me.rblUnits.SelectedValue 'If there is text in the txtSearch TextBox, then search for the new loc...

Custom User Controls and dynamically created web controls events not firing
I have a peculiar problem and since I am just starting to use .net I am confident I am doing something wrong, but I can't see it and I've wasted a lot of time so far trying to figure it out. Hopefully one of you can figure it out. I have a custom User Control and I am dynamically creating a RadioButtonList. If I remove the custom user control from the page the RadioButtonList works as expected and correctly. However, once I add the custom control, it does not fire the SelectedIndexChanged event. Below is some code. If all I do is remove: "<UC:TOPMENU id="TopMenu1"...

Custom composite contorl contains custom contols: controls collection gets empty (Or control get reinitialized) on postback.
Hi, I'm  developing a ASP .Net custom server control library. Where all the basic(Text,check,etc) controls are working well. I have developed an composite control which is more like a Tabular control with the basic custom controls in every cell. The problem is, this composite control reinitializes on post back. I 've added the custom controls (in CreateChildControls method) as cell.controls.add(customcontrol)  row.controls.add(cell) ; this.controls.add(row) Please give me a solution as early as possible IMXO. ASP.NET constructs and reinitializes&n...

Dynamically added control event not firing
In my page load, I call a function that loops through all text boxes, initializes them, and checks their IDs.  If their ID matches certain values, I add an event handler and set AutoPostBack to True.  It works fine if I call my function every time on Page Load.  But if I only call it on NOT Page.IsPostBack (inital load), the event doesn't fire.  Can you post your code here..... If the event is not subscribed on control markup level then you have to subscribe everytime the page is postback.When the going gets tough - the tough gets going------------------------------...

Dynamic control event no getting fired
Ok I just can't seem to work this out, I think I have an ok understanding of the lifecycle but perhaps not.  In short, I'm creating a Button and trying to get it to fire an event, the event handler is never being called. Here's what I've done Declared my button as a Private  On class instantiation: Create the button as new Button(), set the Text property, set an ID Create an EventHandler method with (object sender, Eventargs e) OnInit and also tried Load (both overridden from WebControls.WebControl) added in btnAdd.Click += new EventHandler(myeventbulletpoint3); Anyw...

postback in a dynamically added custom control
I'm sure this question has been asked a million times, but I haven't found anyone who had the specific problem I'm having. I've been having a problem with postbacks on controls that I have created dynamically at runtime. Here's the jist of it: I have a page with a customized menu control that is declared in the .aspx file. When a user clicks on one of the LinkButtons in the menu, it sends an event to the page to load a control dynamically into a PlaceHolder on the page. That part works fine. However, if the control that is loaded into the placeholder has a postback event in it, raisi...

Events Not Firing For Dynamically Added Controls!!
I was wondering if someone has had this same problem and if anyone had any ideas how to make this work. I am dynamically (programatically) adding a LinkButton control and an event handler for it using AddHandler. When the Linkbutton is added in the Page_Load or PreRender methods, the event fires. But if the LinkButton is added via another control event, not only does the event not fire, but my LinkButton disappears. The code is below: <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test.aspx.vb" Inherits="test.test" %><%@ Register ...

Table Cell click event
Hi, I used to have a custom server control inhirted from TableCell control to implement click event in VS.NET 2003.  When I use the custom control in VS.NET 2003 Web application (dynamically adding to table object), everything works fine.  Below is the code from 2003 project, and everything works good in this way.                 Dim c As New MyCustomTableCell                  c.Width = 200     &nb...

Event not getting fired for dynamically generated control.
 I have created a command button dynamically and assigned ItemCommand event for that command button, but that does not seems to get fired. I am unable to find the cause for it. This is the piece of code that I have written to create and assign event to the command button: System.Web.UI.MobileControls.Command cmdDownload = new Command(); cmdDownload.Text = "Download File"; cmdDownload.CommandName = "CommName"; cmdDownload.CommandArgument = "CommArg"; cmdDownload.EnableViewState = true; ...

Web resources about - getting postback events to fire for dynamically added custom controls - asp.net.hosting-open-forum

iPhone 5 A6 chip to dynamically up-clock up to 1.3GHz (and downclock too)?
Interesting video from our friends at TLDToday: If this is not just a Geekbench app glitch, it could indicate why that A6 processor is so 2X ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

iPhone 5 Lightning port dynamically reassigns pins
... of Apple's Lightning USB cable shows that the pins on the plug aren't arranged symmetrically, suggesting that the Lightning port can dynamically ...

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...


A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 12/30/2015 7:04:20 PM