嘿所有我想要得到这个:
<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'。由于其保护级别,它可能无法访问。
答案 0 :(得分:1)
添加一个函数并从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
答案 1 :(得分:1)
打开设计器页面page.aspx.designer.vb
并添加:
Protected theHeadering As String
现在你将拥有一切。
这是自动完成的,但有时,自动部件可能会失败。
以下是创建空WebForms项目的示例。 Full image here
答案 2 :(得分:1)
试试这个
编辑
HTML 代码
<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
答案 3 :(得分:1)
应该是
Public Property theHeadering As String = ""
而不是:
Public theHeadering As String = ""
答案 4 :(得分:0)
我最好的猜测是Mark up代码的Page Directive指向另一个具有相同属性的类 theHeadering As String =“” 但它不是公共访问级别。