在這裏你去:
How to: Reference ASP.NET Master Page Content
從文章,它看起來像
If Master.SQLerror = Nothing Then
InternalSQLErrLabel.Text = ("No Errors Reported")
End If
應該爲你工作。
只要確保按照所述添加了MasterType指令,或者您可能會遇到類型轉換錯誤。 (或者你可以使用你的母版頁類型,而不是法師的變量,如daRoBBie建議在他的回答。)
我創建了一個測試網站只是爲了測試這一點,和它的作品。下面是該網站的全部源:
Site1.Master:
<%@ Master Language="VB" AutoEventWireup="false" CodeBehind="Site1.master.vb" Inherits="WebApplication1.Site1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
This is the Master Page content.
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
Site1.Master.vb:
Public Partial Class Site1
Inherits System.Web.UI.MasterPage
Private _SQLerror As String
Public Property SQLerror() As String
Get
Return _SQLerror
End Get
Set(ByVal value As String)
_SQLerror = String.Empty
End Set
End Property
End Class
WebForm1.aspx的:
<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site1.Master"
CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>
<%@ MasterType VirtualPath="~/Site1.Master" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
This is the Content Page content.
<asp:Label ID="InternalSQLErrLabel" runat="server" Text="Label"></asp:Label>
</asp:Content>
WebForm1.aspx.vb:
Public Partial Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Master.SQLerror = Nothing Then
InternalSQLErrLabel.Text = ("No Errors Reported")
End If
End Sub
End Class
這就是我之前試圖問我的問題,但沒有運氣! ...我得到; SQLError不是system.web.ui.masterpage的成員。 – Phil 2010-02-02 07:54:20
您是否添加了MasterType指令?看起來這可能是你的問題。主屬性不是強類型的,所以它的類型是System.Web.UI.MasterPage,它沒有你的屬性。 – 2010-02-02 07:56:37
我有<%@ MasterType VirtualPath =「〜/ my.master」「%>和 @page MasterPageFile =」〜/ my.master「 – Phil 2010-02-02 08:08:04