0

嘿,我想得到这个:

<div id="subpg_main">    
<%= theHeadering %>
</div>
<!-- END BODY PAGE ------------------------->

在我的 HTML 代码中工作。

后面的代码只有这个:

Public Class thankyou
    Inherits System.Web.UI.Page
    Public theHeadering As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim theName As String = "Bob Barker"
        Dim theEmail As String = "bobb@thepriceisright.com"

        If theForm = "contact" Then
            theHeadering = "<H1>Thank you " & theName & " for contacting us!</H1><BR />"
            theHeadering += "We will be contacting you via your email address at " & theEmail & " within 24 hours."
        End If
    End Sub    
End Class

但是,当我运行该页面时,出现以下错误:

编译器错误消息:BC30451:未声明“theHeadering”。由于其保护级别,它可能无法访问。

4

5 回答 5

2

添加一个函数并从 HTML 调用它

<div id="subpg_main">    
<%= TheHeadering()%>
</div>
<!-- END BODY PAGE ------------------------->



Public Class thankyou
    Inherits System.Web.UI.Page
    Private headering As String = ""

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim theName As String = "Bob Barker"
        Dim theEmail As String = "bobb@thepriceisright.com"

        If theForm = "contact" Then
            headering = "<H1>Thank you " & theName & " for contacting us!</H1><BR />"
            headering += "We will be contacting you via your email address at " & theEmail & " within 24 hours."
        End If
    End Sub    
    Public Function TheHeadering() As String
        Return headering
    End Function
End Class
于 2012-10-15T20:32:54.067 回答
1

打开设计器页面page.aspx.designer.vb

并添加:

Protected theHeadering As String

您现在将一切正常。

这是自动完成的,但有时,自动部分可能会失败。


这是一个创建空 WebForms 项目的示例。完整的图像在这里

在此处输入图像描述

于 2012-10-15T20:36:49.030 回答
1

试试这个

编辑

代码_

<div id="subpg_main">    
<%# TheHeadering()%>
</div>
<!-- END BODY PAGE ------------------------->


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim theName As String = "Bob Barker"
    Dim theEmail As String = "bobb@thepriceisright.com"

    If theForm = "contact" Then
        theHeadering = "<H1>Thank you " & theName & " for contacting us!</H1><BR />"
        theHeadering += "We will be contacting you via your email address at " & theEmail & " within 24 hours."
    End If
   'Bind your expression with the markup code
   Me.DataBind()
End Sub    
于 2012-10-15T20:37:44.460 回答
1

它应该是

 Public Property theHeadering As String = ""

并不是:

 Public theHeadering As String = ""
于 2012-10-15T21:01:29.733 回答
0

我最好的猜测是标记代码的页面指令指向另一个类,该类具有相同的属性 theHeadering As String = "" 但它不是公共访问级别。

于 2012-10-15T20:34:51.230 回答