![](/img/trans.png)
[英]ASP.NET:Create dynamically Masterpage and aspx page in runtime in code behind?
[英]ASP.NET - How to get and set MasterPage attribute in page code behind?
我有一個使用MasterPage的ASP.NET頁面。 我在MasterPage中有一個public
bool
屬性,稱為ShowChangePassword
。 我想在使用此MasterPage的頁面中將其設置為true或false。
我有以下代碼,但無法設置屬性:
var masterPage = this.Master;
masterPage.ShowChangePassword = false;
我需要什么代碼?
您需要對母版頁類的類型化引用。 在您的內容頁面中放入類似的內容:
<%@ Page masterPageFile="~/MasterPage.master"%>
<%@ MasterType virtualPath="~/MasterPage.master"%>
然后,您可以執行以下操作:
this.Master.ShowChangePassword = false;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.