Labels

Friday, March 7, 2008

Events in User Control/Master Page

Hi,

To communicate between UserControl / Master Page and the Container Page, normally we use Event Raise mechnaism. In this mechanism, we first declare the delegate and then an event of declared delegate type. Then on some event in UserControl/Master we raise our custom event.

Instead of getting into all such things better to use only the ‘Delegate’ approach as below.

Code in User Control:

private Delegate mSearchResult = null;

public Delegate SearchResult

{

set

{

mSearchResult = value;

}

}

protected void btnSearch_Click(object sender, EventArgs e)

{

mSearchResult.DynamicInvoke();

}

Code in container Page:

protected void Page_Load(object sender, EventArgs e)

{

delegate void SearchResult(Dto.Stipulation dtoStupulation);

SearchResult searchResultCall = new SearchResult(this.GetSearchData);

this.UserControlName.SearchResult = searchResultCall;

}

private void GetSearchData(Dto.Stipulation dtoStupulation)

{

}

Thanks & Regards,

Arun Manglick || Tech Lead

No comments:

Post a Comment