문제

I have a usercontrol that acts as a container to hold more usercontrols within it.

I need to perform certain access checks once all of the child controls have databound.

I was hoping I could attach to a usercontrol.databound event but there does not seem to be one.

What other options do I have to do something on the parent usercontrol once the other usercontrols have databound. I assume I have to get the child controls to notify the parent they have databound and the parent will need to track which have databound and which have not and when they all have databound it can peform its action.

도움이 되었습니까?

해결책

You don't need to get the child controls to notify the parent. Look at the ASP.Net Page :Life Cycle. You need to put the code in the container user control in the PreRender event. This executes after the postback events.

다른 팁

Based on ASP.net Page Life Cycle Events article I have used this:

protected void Page_PreRenderComplete(object sender, EventArgs e)
{
  if (!IsPostBack) //only at 1st load
    UpdateSelection();
}

protected void UpdateSelection()
{
  UpdateSelection(listItems.SelectedValue);
}

protected void listItems_SelectedIndexChanged(object sender, EventArgs e)
{
  UpdateSelection();
}

In my case, UpdateSelection was loading XML data from a file selected at a dropdown list (which at start is pointing to index 0) and needed some CheckBoxLists on the page to have first gotten their items from other XML files so that they would allow the code to check items on them based on the XML data

From then on UpdateSelection is just getting called at the dropdownlist SelectedIndexChanged event (those do PostBacks so at PreRenderComplete I ignore them to avoid doing UpdateSelection twice)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top