Source: Figer's Technology Blog

Figer's Technology Blog C# eventhandler passing variables from Usercontrol to parent page

In this example I'm passing a telerik radgrid collection to the parent page from the child usercontrol when the user selects a row.-----------------------------User Controls (.ascx)-----------------------------public partial class NPISearch : System.Web.UI.UserControl //This is just the standard class section when a user control is created</em>{<strong>public delegate void ReturnNPISearchEvent (Telerik.Web.UI.GridDataItemCollection e); //You need to add this line</strong>Page_Load() { //Standard Page_load eventprotected void grdNPI_SelectedIndexChanged(object sender, EventArgs e) //Here is the function that raises the event to the parent page{//Null check makes sure the main page is attached to the eventif (this.ReturnNPISearch != null)this.ReturnNPISearch(grdNPI.MasterTableView.Items);}}-----------------------------------Parent page (.aspx)---------------------------------protected void Page_Load(object sender, EventArgs e) //Add the line below in Page_Load(){NPISearch1.ReturnNPISearch += new MCRASunshine.Account.NPISearch.ReturnNPISearchEvent(MyEventHandlerFunction_ReturnNPISearch);}//This is the function that is called when the usercontrol event is firedpublic void MyEventHandlerFunction_ReturnNPISearch(Telerik.Web.UI.GridDataItemCollection e){this.divSearch.Visible = false;this.divAddInfo.Visible = true;txtInfoNPI.Enabled = false;//set values in textboxesforeach (Telerik.Web.UI.GridDataItem dataItem in e){if (dataItem.Selected == true){this.txtInfoFirstName.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dataItem.Cells[4].Text.ToLower().Trim('"'));this.txtInfoLastName.Text = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(dataItem.Cells[3].Text.ToLower().Trim('"'));this.txtInfoNPI.Text = dataItem.Cells[5].Text.Trim('"');

Read full article »
Est. Annual Revenue
$25-100M
Est. Employees
100-250
CEO Avatar

CEO

Update CEO

CEO Approval Rating

- -/100



Figer's Technology is a Private company. Figer's Technology generates $238.5K in revenue per employee Figer's Technology has 1 followers on Owler.