Reputation: 10542
Hey all i am trying to get this:
<div id="subpg_main">
<%= theHeadering %>
</div>
<!-- END BODY PAGE ------------------------->
To work within my HTML code.
The code behind just has this:
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 = "[email protected]"
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
However, when i run the page i get the following error:
Compiler Error Message: BC30451: 'theHeadering' is not declared. It may be inaccessible due to its protection level.
Upvotes: 0
Views: 15179
Reputation: 10542
It should be
Public Property theHeadering As String = ""
And not:
Public theHeadering As String = ""
Upvotes: 1
Reputation: 75083
open the designer page page.aspx.designer.vb
and add:
Protected theHeadering As String
you will now have everything working.
This is done automatically, but sometimes, the automatic part can fail.
Here is an example creating an empty WebForms project. Full image here.
Upvotes: 1
Reputation: 3274
Try with this
EDIT
HTML CODE
<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 = "[email protected]"
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
Upvotes: 1
Reputation: 4585
Add a function and call it from the 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 = "[email protected]"
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
Upvotes: 2
Reputation: 336
My best guess is that the Page Directive of the Mark up code is pointing to another class which the have the same property theHeadering As String = "" but its not a Public access level.
Upvotes: 0