ASP.Net ListView and event handling.

Posted by Neil on Stack Overflow See other posts from Stack Overflow or by Neil
Published on 2009-09-05T18:01:45Z Indexed on 2010/04/19 6:03 UTC
Read the original article Hit count: 438

Filed under:
|
|
|

I have an .ascx which contains a listview. Let's call it the parent. Within its ItemTemplate I reference a second .ascx which is basically another listview, let's call it the child. On the parent, the child control is wrapped in a placeholder tag. I use this place holder tag to show and hide the child.

Psuedo code:

The child listview has a 'close' button in its Layout Template. Let's call it "btnClose" with an onClick event of "btnClose_Click". I want to use this button to set the visibility of the containing placeholder.

I'm trying to avoid doing something like using PlaceHolder plhChild = (PlaceHolder)childListCtl.NamingContainer since I can't guarantee every instance of the child .ascx will be contained within a placeholder.

I tried creating an event in the child that could be subscribed to.

Psuedo code:

public delegate CloseButtonHandler(); public event CloseButtonHandler CloseButtonEvent;

And in the actual btnClose_Click(Object sender, EventArgs e) event I have:

if (CloseButtonEvent != null) CloseButtonEvent();

My problem is that the delegate CloseButtonEvent is always null.

I've tried assigning the delegate in the listview's OnDatabound event of the parent and on the click event, to set the plhChild.visible = true, and I've stepped through the code and know the delegate instantiation works in both place, but again, when it gets to the btnClose_Click event on the child, the delegate is null.

Any help would be appreciated.

Neil

© Stack Overflow or respective owner

Related posts about event

Related posts about delegate