[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2007-11-16
2
Medium Priority
?
657 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

656 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