0

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.

2
  • Did you forget to compile after adding the field? Commented Oct 15, 2012 at 20:24
  • running it in debug mode, @HackedByChinese Commented Oct 15, 2012 at 20:24

5 Answers 5

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Error in code theHeading is already declared as private theHeading As String
Did you compile before testing? I have just created a website with this code and it worked fine for me.
1

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    

2 Comments

@StealthRT you have to replace = for #
Changed to <%# theHeadering()%> and now it says Argument not specified for parameter 'index' of 'Public ReadOnly Default property Chars(index as Integer) As Char
1

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.

enter image description here

5 Comments

then it's something wrong with your compilation part, just created a new VB.NET Webforms project and wrote what you see, and works as you can see.
Isn't making changes to the designer file a bad idea?
@ShaiCohen not if you know what you're doing :)
I don't like what you are insinuating .... but then again 23.8k vs 1k :) Seriously though, doesn't VS automatically write to that file and thus can overwrite any change you make? Or, more importantly, it signals that something is "corrupt" with the solution/project?
@ShaiCohen it's a merely helper file that holds the variables in use, when you normally drag and drop controls directly to the visual page (and I stop doing that several years ago - the visual thingy). It helps to track those objects, and I have plenty old projects that when I need a new user control or a merely string to hold a variable I do need to add it to the designer page before I can compile.
1

It should be

 Public Property theHeadering As String = ""

And not:

 Public theHeadering As String = ""

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.