简体   繁体   English

从Master更新内容页面

[英]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 谢谢

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 ): 内容页面(假设它的类型称为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
}

For the sequence of events, see http://msdn.microsoft.com/en-us/library/ms178472.aspx . 有关事件序列,请参阅http://msdn.microsoft.com/en-us/library/ms178472.aspx Specically, " Master pages behave like child controls on a page: the master page Init event occurs before the page Init and Load events, and the master page Load event occurs after the page Init and Load events. " 特别是,“ 母版页的行为类似于页面上的子控件:母版页Init事件发生在页面Init和Load事件之前,母版页Load事件发生在页面Init和Load事件之后。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM