How do I add events to nested server controls? (ASP.Net)

Posted by bert on Stack Overflow See other posts from Stack Overflow or by bert
Published on 2010-05-18T11:35:41Z Indexed on 2010/05/18 11:41 UTC
Read the original article Hit count: 128

Filed under:
|
|

I am building a custom master page type control i.e. sort of like a datagrid but should be easier to add custom functionality into it. It's going great but part of the desired functionality is to have a paging control that switches on and off and part of that control would be a textbox that displays the current page number and on TextChanged redirects to the new page of the dataset.

The problem I'm having is that technically the textbox which has its event fired is embedded in a control that is embedded in the control you actually put on the page sort of like

Page
 |
Display Control
 |
Paging Control
 |
Textbox

Buried all the way down there the event is not firing. Worse the postback javascript isn't even being written onto the page (Nothing on the page posts back so far this is the only bit that really needs to).

I've been trawling around Google for quite a while now and picked up that I need to implement INamingContainer (done) and I need to add the control into the page's control tree (is Pre_Init too late for that? When's a good time to Add the Control to the page?) then the event should fire, apparently. But I've been unable to find an example of best practice on this there are quite a few near misses where people are having button angst but this isn't a button.

So can anyone point me in the direction of getting a control embedded in a control embedded in a control added to a page to behave properly?

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET