name 'a' is not declared

B

Ben

Hi,

in code-behind, i have:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim a As Integer
a = 5
End Sub

i want to use that variable in the aspx file:

<body>
<form id="form1" runat="server">
<%=a%>
</form>
</body>

but i get the error: name 'a' is not declared.

Where and how do i have to declare 'a'?

Thanks
Ben
 
G

Göran Andersson

Ben said:
Hi,

in code-behind, i have:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load
Dim a As Integer
a = 5
End Sub

i want to use that variable in the aspx file:

<body>
<form id="form1" runat="server">
<%=a%>
</form>
</body>

but i get the error: name 'a' is not declared.

Where and how do i have to declare 'a'?

Thanks
Ben

You are declaring the variable as local in the method. To access if from
the aspx code you have to declare it as a protected (or public) member
of the class intead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,965
Messages
2,570,148
Members
46,710
Latest member
FredricRen

Latest Threads

Top