Solved

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

Posted on 2007-11-16
2
654 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

689 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