Solved

Server controls inside a composite control do not fire events within control

Posted on 2007-11-16
2
644 Views
Last Modified: 2012-08-13
With much pain i have created a custom control which renders the control with a decent look and feel. I could possibly handle that. But the matter of concern is that the server controls (i have many listbox to name one) are not invoking any events. I will explain more about the custom control. It is quite a simple custom control that inherits from CompositeControl and INamingContainer. The control has an asp.net button and an asp.net listbox server control. In the CreateChildControls method of the CustomControl - ImagePicker is its name, i have associtated the selectedindexchanged event on the listbox. The behaviour at runtime is weird. The page which hosts the CustomControl posts back successfully, but the event is never invoked. Note that the event handler is also inside the control itself. I am not talking about exposing the events to the external world which i know will require me to implement the interfaces IPostBackDataHandler and IPostBackEventHandler. I have infact implemented those interfaces just in case i understood it wrong, but it wont help.
Following is the code that i added in CreateChildControls method:

            listCategories = new ListBox();
            listCategories.Height = Unit.Pixel(120);
            listCategories.AutoPostBack = true;
            listCategories.BackColor = Color.Gray;
            listCategories.BorderStyle = BorderStyle.None;
            listCategories.BorderWidth = 0;
            listCategories.EnableViewState = true;
            this.Controls.Add(listCategories);
            listCategories.SelectedIndexChanged += new EventHandler(listCategories_SelectedIndexChanged);

The method listCategories_SelectedIndexChanged is never fired. Neither the SelectedIndex of the listbox gets changed.
0
Comment
Question by:sudhijss
2 Comments
 
LVL 33

Expert Comment

by:raterus
ID: 20300468
Just go ahead and post all the code of your composite control, and all the code of the aspx page you are using this control in.  It is possible to do what you want without anything too fancy.
0
 
LVL 1

Accepted Solution

by:
sudhijss earned 0 total points
ID: 20301016
Got it! Must have been a stupid mistake i guess. I was adding items to the list inside the RenderContents method. I moved that databinding code to the CreateChildControls and lo the event fires. I must ve not understood the page lifecycle appropriately. Thanks for offering help anyway.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now