[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1164
  • Last Modified:

Asp.net label not declared

Hi, im fairly new to asp.net and i need some help fixing my code for test.aspx (all on one page, no codebehind), heres the page:

<%@ Page Language="vb" %>
<%@ import Namespace="System" %>
<%@ Import Namespace="System.Data" %>

<script Language="VB" Debug="true" RunAt="Server">
Private Sub Page_load (byval sender as system.object, byval e as system.eventargs) handles mybase.load
      'Protected WithEvents lblresult As Label.
        dim strchoice as string
      strchoice = "one"
      lblresult.text = strchoice
End sub

Private sub mysub(byref strtemp as string)
      strtemp= "two"
End sub

<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
<meta name="GENERATOR" content="Microsoft FrontPage 6.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<form runat="server">
<asp:Label id="lblResult">

when i run it i get this error:
Compiler Error Message: BC30451: Name 'lblresult' is not declared.
ive tried:
"dim lblresult as label" and "Protected WithEvents lblresult As Label."
I dont know what is wrong, but i know it should be fairly easy to fix. Do i need to make a class for this thing work, cause i dont think i should (its asp.net 1.1)? Dont worry about the byval and byref, that was what i was planning to test before i got that error. Help please, thanks
2 Solutions
<asp:Label id="lblResult" runat="server">
<asp:Label id="lblResult" runat="server">  (You were missing runat attribute)

You don't have to declare it. You can directly access it with the label Id i.e. lblResult.

In case you use Code Behind :
For Visual Studio 2003
you have to declare the variable in the code behind file.

For Visual Studio 2005
controls are declared in the code behind designer file.

Featured Post

Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now