Qui si va:
How to: Reference ASP.NET Master Page Content
Dall'articolo, sembra che
If Master.SQLerror = Nothing Then
InternalSQLErrLabel.Text = ("No Errors Reported")
End If
dovrebbe funzionare per voi.
Basta assicurarsi di aggiungere la direttiva MasterType come descritto o si potrebbe ottenere un errore di conversione del tipo. (Oppure potresti usare una variabile del tuo tipo di pagina master invece di Master, come suggerisce daRoBBie nella sua risposta.)
Ho creato un sito Web di prova solo per testarlo e funziona. Ecco il sorgente completo del sito:
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
fonte
2010-02-02 07:50:11
Questo è quello che stavo cercando prima di fare la mia domanda, ma senza fortuna! ... ottengo; SQLError non è un membro di system.web.ui.masterpage. – Phil
Hai aggiunto la direttiva MasterType? Sembra che potrebbe essere il tuo problema. La proprietà Master non è fortemente tipizzata, quindi è di tipo System.Web.UI.MasterPage, che non ha la tua proprietà. –
Ho <% @ MasterType VirtualPath = "~/my.master" "%> e in @page MasterPageFile =" ~/my.master " – Phil