views:

348

answers:

1

I want to make use of "complex" usercontrols with more than one control element within. Its the same control I will reuse in the list and I have a PlaceHolder control for it already.

I can add the control with LoadControl(path to .ascx) - no problem.

I can thru my custom properties get/set access the embedded Labels too, so I can initialize each control perfectly.

But when adding LinkButtons I get into trouble/problems.

When I click the button, I do get a "submit" of the page rendering the controls, but the control's own button event does not seem to fire (or at least PageLoad on the parent page seems to fire first?) - I cant figure out where my event goes or where to look for a name/ID or parametre for this button.

Howcome or what am I doing wrong here?

I've made a "fake button" now by using a label more with a "hardcoded A HREF" with an ID in the URL, but I would like to learn what event I need to catch and where or how to init the button, because I want to be able to use "default ASP.NET" controls for these usercontrols (hopefully without too much patchwork-coding)...

A: 

The only reason that events get "lost" is because your controls are not being recreated in such a manner that ASP.Net can associate the event with the control after the postback. It does so through the use of the ID property.

In other words, you're doing one of three things wrong:

1) You're assigning the ID's of your linkbuttons differently during the creating phase in Init after the postback

2) You're creating your linkbuttons dynamically using code, but you're doing it after the Init phase of the page lifecycle, so that your controls do not participate in ViewState.

3) You're re-binding the datasource of the parent control containing the linkbuttons on every postback. Use if (!IsPostBack) to prevent rebinding it every time.

Without seeing your code I can't give anything more specific than that unfortunately.

womp
The controls are build perfectly (visually) on PageLoad first time. Which is what I am after. But the usercontrol has buttons and it's these events I need to grab when clicked. ... but my comment above says it all. Thanks for your time and sorry.
BerggreenDK
Sorry for the long delay, but the project got canceled. I have investigated though. It seems that it was the AJAX.NET combined with Masterpages which did the "trick".
BerggreenDK