neil

neil

  • NA
  • 1
  • 0

User control with ListView and event wiring.

Sep 5 2009 11:46 AM
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:

<asp:Placeholder id="plhChild" runat="server" visible="false" >
    <uc0:childList id="childListCtl" runat="server" />
</asp:Placeholder>

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 that set's 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

Answers (1)