Solved

label not declared?

Posted on 2006-10-26
14
474 Views
Last Modified: 2012-05-05
How come? All other pages in this app are allowing me to set a labels text property by using lblName.Text = someVarname in the .vb file.
What am I missing here (only diff is this page in it's own folder but still off the apps root and within the VS2005 solution)

.aspx page
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblSession" runat="server" Text=""></asp:Label>
    </div>
    </form>

code behind
Partial Class Wapps_Default
    Inherits System.Web.UI.Page
    Dim instance As HttpSessionState
    Dim value As String
    lblSession.text = instance.value
End Class

error: declaration expected (lblSession)
0
Comment
Question by:QPR
  • 6
  • 4
  • 3
  • +1
14 Comments
 
LVL 4

Expert Comment

by:Xeavn
ID: 17815296
Do you have it declared at the top of the code behind? If not put this up in your variable declaration.

Protected WithEvents lblSession As Label

0
 
LVL 29

Author Comment

by:QPR
ID: 17815383
Strange not needed to do that in the other pages... however

Partial Class Wapps_Default
    Inherits System.Web.UI.Page
    Protected WithEvents lblSession As Label
    Dim instance As HttpSessionState
    Dim value As String
    lblSession.text = instance.value
End Class

gives the error: lblsession is already declared as protected dim withevents lblSession as system.web.ui.webcontrols.label in this class
0
 
LVL 12

Expert Comment

by:Pra4444
ID: 17815398
in vs 2005, you dont have to declare at both the places(aspx and the code behind..)...so i am guessing its not the error..
0
 
LVL 29

Author Comment

by:QPR
ID: 17815526
the only declaration(s) are in the code behind.
This was just a test page the entire code for both pages is here:

default.aspx.vb
Partial Class Wapps_Default
    Inherits System.Web.UI.Page
    Protected WithEvents lblSession As Label
    Dim instance As HttpSessionState
    Dim value As String
    lblSession.text = instance.value
End Class
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Wapps_Default" %>

default.aspx
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblSession" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>
0
 
LVL 12

Accepted Solution

by:
Pra4444 earned 250 total points
ID: 17815547
dont you have to put the following line
lblSession.text = instance.value

in a page_load or button click function or something???
you just have it hanging in there inside the class....???
0
 
LVL 29

Author Comment

by:QPR
ID: 17815622
ok I changed the code to this
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim instance As HttpSessionState
        Dim SIDvalue As String = instance.SessionID
        lblSession.Text = SIDvalue
    End Sub

now it says that instance is used before being assigned a value and a null value could cause exception.
How can I get past this? When I try to run it I get the error "Object reference not set to an instance of an object."
0
 
LVL 12

Expert Comment

by:Pra4444
ID: 17815703
i am not familiar with httpsession..

but generally you encounter this error when you fail to instantiate...you are missing a 'new' keyword somewhere..that would be my guess..
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17815748
The line:

    Dim SIDvalue As String = instance.SessionID

Should probably say:

    Dim SIDvalue As String = Session.SessionID

As I assume you want to get the ID of the current Session. You currently declare an object of type HttpSessionState, but don't assign anything to it, but I guess you meant to use the existing Session object.
0
 
LVL 29

Author Comment

by:QPR
ID: 17815828
I just want to get the current sessionID, this was a test page I plan to use the ID in an app I'm making.
I looked up VS2005 help on how to get it in asp.net 2.0 and got this example...

Dim instance As HttpSessionState
Dim value As String
value = instance.SessionID

If anyone knows a better/working way I'm all ears.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17815840
As I mentioned in my last post:

    Dim SIDvalue As String = Session.SessionID
0
 
LVL 29

Author Comment

by:QPR
ID: 17815845
sorry missed that - works perfectly!
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17815855
Erm, not that i'm really bothered but, how come all the points went to Pra4444 ?
0
 
LVL 29

Author Comment

by:QPR
ID: 17815885
Sorry I felt a bit mean when I did it but.... my intial question was regarding the label not being declared.
His post said that it had to be declared within a page event which was what fixed my problem - the sessionID bit was a spin off and never part of the original question.
I do very appreciate you providing the correct answer for the second question.
I can set up a dummy question and award you the points for it if you like - does that break EE rules?
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17815902
Don't worry about it, like I said i'm not all that bothered; it's just that, ordinarily, if you add a spin-off question that gets answered then people usually split the points.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
File Upload Control on a ASP.NET Overlay Page 1 42
Re-position sub-options beneath the TAB 7 77
Name space syntax error 12 44
Error on Add method 1 38
AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now