Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update Content Page from Master

I have a master page and a content page. Not quite sure how to do this. How do I reset/refresh the content page after I do something in the Master page. The something I'm doing is changing a dropdown list and which then dictates what you can see in the content page. If I could call the page load of the content page from the master page that would do it.

Thank you

like image 409
MindGame Avatar asked Feb 27 '26 11:02

MindGame


1 Answers

Handle a custom event of the masterpage in the page.

//Event in MasterPage
public delegate void SomethingSelected(object sender, String SelectedValue);
public event SomethingSelected OnSomethingSelected;

//SelectedIndexChanged event in MasterPage
protected void DropDonwnList1_SelectedIndexChanged(object sender, EventArgs e)
{
    OnSomethingSelected(sender, ((DropDownList)sender).SelectedValue);
}

The content page(assuming the type of it is called SiteMaster):

protected void Page_Init(object sender,EventArgs e){
    var master = (SiteMaster)Page.Master;
    master.OnSomethingSelected +=  MasterSelected;
}

private void MasterSelected(object sender, string selectedValue)
{ 
    // now you can handle the master's event and update your content page
}
like image 62
Tim Schmelter Avatar answered Mar 01 '26 23:03

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!