2010-04-14 72 views

回答

4

你掌握这将定义你的属性页,您应该使用一个基类:

public class BaseMasterPage : System.Web.UI.MasterPage 
{ 
    public string HomeUrl {get; set; } 
} 

然后你的母版页应该从这个BaseMasterPage类继承(为例):

// real master page 
public partial class Common_MasterPages_Backend_Default : BaseMasterPage 
{ 
} 

之后,您可以通过Page.Master访问您的财产:

BaseMasterPage baseMaster = (BaseMasterPage)Page.Master; 
string homeUrl = baseMaster.HomeUrl; 

从使用此母版页的任何页面。

1

你可以使用继承来做到这一点。

假设这样的:

  • 你的主人叫Med_Instrumento.Master
  • 你的网络内容被称为Med_Instrumento1.aspx

您可以创建另一个页面(比如Instrumentobase.aspx),并放在那里所有你喜欢的公共/受保护的属性。此页面也必须使用主页面。

之后,将您的Med_Instrumento1.aspx类更改为从此页面继承。

例如:这里是代码: 的webcontentpage:

<%@ Page Language="C#" MasterPageFile="~/Med_Instrumentos.Master" AutoEventWireup="true" CodeBehind="Med_Instrumento1.aspx.cs" 

后面的代码:

public partial class Med_Instrumento1 : InstrumentoBase 

的基类:

<%@ Page Language="C#" MasterPageFile="~/Med_Instrumentos.Master" AutoEventWireup="true" CodeBehind="InstrumentoBase.aspx.cs" Inherits="Auscultacion.InstrumentoBase" Title="Untitled Page" %> 

后面的代码:

public partial class InstrumentoBase : System.Web.UI.Page 
    { 

    public string INST_Emplazamiento 
    { 
      get {return "Some Value" );} 
    } 
    public TextBox DevolverTextBoxdeMaster(string sNombreTextBox) 
      { 
      TextBox Texto; 
      Texto = (TextBox)Master.FindControl(sNombreTextBox); 
      return Texto; 
      } 
} 

在您的Med_Instrumento1.aspx中,您可以使用INST_Emplazamiento属性或DevolverTextBoxdeMaster方法。

相关问题