简短的回答是 PreRender,但听起来您可以从将母版页的一些逻辑移动到业务对象/类中受益?拥有相互依赖的不同母版页可能不是最好的主意。如果您需要数据在全球范围内可用 - 将其加载到业务类中,并在创建后将其缓存到合适的时间(如果仅用于请求,请使用 HttpContext.Items)。
如果您确实需要坚持该设置,您还可以选择通过母版页层次结构调用 - 因此您的根主控(顶级)可以使选项/数据在 OnInit 可用。然后可以调用任何其他需要它的东西 - 这是一个循环任何给定页面层次结构中的所有母版页并返回所需类型的第一个实例的方法:
/// <summary>
/// Iterates the (potentially) nested masterpage structure, looking for the specified type.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="currentMaster">The current master.</param>
/// <returns>Masterpage cast to specified type or null if not found.</returns>
public static T GetMasterPageOfType<T>(MasterPage currentMaster) where T : MasterPage
{
T typedRtn = null;
while (currentMaster != null)
{
typedRtn = currentMaster as T;
if (typedRtn != null)
{
return typedRtn; //End here
}
currentMaster = currentMaster.Master; //One level up for next iteration
}
return null;
}
要使用:
Helpers.GetMasterPageOfType<GlobalMaster>(this.Master);