我有masterpage.master.vb,我有属性,如;
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
然后我有一个aspx页面,我需要在其中使用此属性,例如;
If **[masterpage property sqlerror]** = Nothing Then InternalSQLErrLabel.Text = ("No Errors Reported") End If
任何人都可以给我一个想法如何去做?我试过搜索,但大多数文章都在网页控件的上下文中讨论……
谢谢.
解决方法
干得好:
How to: Reference ASP.NET Master Page Content
从文章来看,它看起来像
If Master.SQLerror = Nothing Then InternalSQLErrLabel.Text = ("No Errors Reported") End If
应该适合你.
只需确保按照描述添加MasterType指令,否则可能会出现类型转换错误. (或者您可以使用主页类型的变量而不是Master,就像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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。