.NET基礎之主版頁面應用

來源:互聯網
上載者:User

@ Master:定義 ASP.NET 頁分析器和編譯器使用的特定於主版頁面(.master 檔案)的屬性。詳見MSDN相關屬性。

1.建立簡單的嵌套主版頁面
首先建立一個主版頁面做主主版頁面,再建立一個主版頁面,並選擇主主版頁面為其母片,則完成嵌套,主要應用於主網站中嵌套分類母片。

 

2.訪問主版頁面上的控制項
Master:擷取嵌套主版頁面方案中當前主版頁面的父級主版頁面
FindControl:在當前的命名容器中搜尋帶指定 id 參數的伺服器控制項

1protected void Page_LoadComplete(object sender, EventArgs e) 
2    { 
3        Label mlabel = (Label)this.Master.FindControl("labMaster"); 
4        this.Label1.Text = mlabel.Text; 
5    }
6

 

3.訪問主版頁面上的屬性

  • 在主版頁面的cs代碼中定義一個公用屬性。

    string mValue = "";
        public string MValue
        {
            get
            {
                return mValue;
            }
            set
            {
                mValue = value;
            }
        }

  • 在主版頁面的原始碼中可以引用該屬性,放在任意位置即可<%=this.MValue %> ,也可以用控制項來顯示。
  • 在內容頁的原始碼中添加<%@ MasterType VirtualPath="MasterPage.master" %>:提供一種方法,用於當通過 Master 屬性訪問 ASP.NET 主版頁面時,建立對該主版頁面的強型別引用。
  •  在內容頁的cs代碼中

    protected void Page_Load(object sender, EventArgs e)
        {
            Master.MValue = "Welcome";
        }

     

     

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.