从ASP.net VB子页面访问母版的属性 [英] Accessing masterpage properties from child pages in ASP.net VB

查看:204
本文介绍了从ASP.net VB子页面访问母版的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经masterpage.master.vb在那里我有属性,如;

I have masterpage.master.vb where I have properties, such as;

 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页面等;

Then I have an aspx page in which I need to use this property in, such as;

 If **[masterpage property sqlerror]** = Nothing Then
            InternalSQLErrLabel.Text = ("No Errors Reported")
        End If

谁能给我一个想法,如何去了解呢?我试图寻找,但大多数文章在Web控件的背景下谈...

Can anyone give me an idea how to go about this? I've tried searching but most articles talk in the context of web controls...

感谢。

推荐答案

在这里你去:

如何:参考ASP.NET母版页内容

从文章,它看起来像

If Master.SQLerror = Nothing Then
    InternalSQLErrLabel.Text = ("No Errors Reported")
End If

应该为你工作。

只要确保描述添加中的MasterType指令,或者你可能会得到一个类型转换错误。 (或者你可以用你的母版页类型,而不是法师的变量,如daRoBBie建议在他的回答。)

Just be sure to add the MasterType directive as described or you might get a type conversion error. (Or you could use a variable of your master page type instead of Master, as daRoBBie suggests in his answer.)

我创建了一个测试网站只是为了测试这一点,和它的作品。下面是该网站的全部源代码的:


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

这篇关于从ASP.net VB子页面访问母版的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆