Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

INamingContainer - CreateInstance of Composite Control 1

Status
Not open for further replies.

skillo

MIS
Apr 5, 2001
18
US
Hey Guys,

Need some help!! I have numerous composite controls that I need to render based on what step in a wizard that a user is at. These controls will be rendered 1 at a time. I have created my templated composite controls and am using the Activator.CreateInstance to create which ever control needs to be created. The creation of the controls and rendering isn't a problem. I run into issues trying to capture the events coming off child controls (buttons, etc...) within the composite control that is being displayed. I have the INamingContainer interface in place to create unique ids for the child controls, but when you look at the "View Source" of the rendered page the name given to these inner most child controls are not showing an elongated name, like the parent controls are showing.

One of my parent controls has a name: "Left:blah_blah_blah:_ctl0:ctl1"

One of my inner-most child buttons has a name of: "_ctl2"

It just seems really strange that the inner most control has such a short name, being that the INamingContainer (I thought) was suppose to be pinpointing the location of the control.

Is this normal or am I totally losing it??

Any thoughts or help is greatly appreciated!!
 
I had similar problems where I couldn't get events to fire.

I was building a composite control and using CreateChildControls and DataBind methods to create my control.

I found that the only place I could get events to fire was if I created them in the CreateChildControls method.

So if it helps try wiring up handlers in that method.

Sorry that is all I can help with
rotsey
 
Hey Rotsey!!

Thanks for the response, I really do appreciate it. Currently, I do have the eventhandlers setup right after I create and add the controls in CreateChildControls. This just seems so simplistic that it's just about to drive me crazy!! The control itself works on it's own as a standalone, but when I create an instance of it with Activator.CreateInstance, from what I have read, it doesn't have it's normal Life cycle events. It just seems that the eventhandlers aren't sticking for some reason or another. I started looking to make sure that I had the INamingContainer defined everywhere and noticed the differences in the naming of the inner most controls was a lot more simplistic than the parent controls. May be nothing but just seemed strange.

I'm thinking about creating a generic method within the composite control itself to wire the events once the control has been rendered. We'll see what this does and I'll get back with the results. Any other thoughts and I'm at the point of trying just about anything.
 
Unfortunately I cannot add any more.

Goodluck skillo

rotsey
 
Hey Rotsey!!

Ok, taking into account your thoughts about creating the controls in CreateChildControls and the thoughts I was thinking about the LifeCycle has gotten me through this!! Thank you so much!!!

The controls that we are rendering were going to be dynamically loaded based on what step we are in in the wizard. Which means when we go through Creating our child controls we are not going to know which control to dynamically create. I had it coded to create an instance of the control in the render method of my parent control. The more I got to thinking about the lifecycle and your notes, I decided to try and remove all settings within the render method of the parent control and create the instances of the controls as a response to events and in the OnInit of the parent control. And now, as I am dancing, the composite control of the createinstance is responding perfectly.

Thanks so much for your time and effort!!
Have a GREAT New Year!!
Stacy
 
Great to hear Stacy.
You too have a happy new year.
rotsey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top