question about declaring labels and errors from VWDeveloper

J

Jon Paal

When I add a label to my page like this :

<asp:Label id="Message" Text="" Runat="Server"/>

and code like this:

Sub Page_load( s As Object, e As EventArgs )
Message.Text = " whatever "
End sub

I get a error warning from Visual Web Developer that says "Name 'Message' is not declared"

how do I declare the asp:label ?
 
M

Mr Newbie

If you did this manually, then there would be no declaration in the code
behind class and therefore your code would not see it.
use the designer to add the code. If you dont have a designer, then you
will need to declare this in code behind at class level

Protected WithEvents lblMessage As System.Web.UI.WebControls.Label

Remember, your aspx page is actually a class template which inherits from
the code behind class, if you look in the page declarations on your aspx
page at the top you will see this.

HTH
 
J

Jon Paal

interesting. This appears to be a VWD thing, which does have a designer, but I added everything manually into the source page.

I also don't use code behind, which is a valid option in VWD. So, when I drag the label from the toolbox into the source page (or
design page) VWD does not automatically add anything else.

However, when I drag the code into the page from the tool box, then add the script code manually, the error message does not appear.

Go figure........
 
M

Mr Newbie

By VWD, you mean what ?

In any case, in order to address a class member, it must be have been
declared in the first place, this goes without saying really. I'm not really
sure how your setup is configured and what tools you are using so its a
little difficult.
 
M

Mr Newbie

OK, I dont have much experience with that yet, however, you say you dont use
code behind. You do, trust me! 2005 uses partial classes, so you wont
necessarily see the designer code, its made that way to seperate you from
what the designer is doing,

Are you using beta code still or release ?
 
J

Jon Paal

it's the release version.

If it's hiding code somewhere, then I have no idea what to do for these problems.
I can only refer to files/code in the website that are visible to me.
 
J

Jim Cheshire

Mr said:
OK, I dont have much experience with that yet, however, you say you
dont use code behind. You do, trust me! 2005 uses partial classes, so
you wont necessarily see the designer code, its made that way to
seperate you from what the designer is doing,

Are you using beta code still or release ?

Newbie,

Couple of clarifications. You do not have to declare the label. ASP.NET
does that at runtime. That's the whole point behind partial classes. One
other minor point... you really wouldn't want to declare a label with the
WithEvents keyword since the label doesn't really have any events that you
would want to handle.

It is certainly possible to not use code-behind in both VWD and VS 2005.

As to the OP's point, can you post all of your code copied and pasted into a
message? What you've entered here should work fine.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry: Digging into Objects
Describes the details of digging into
memory usage with the debugger.
 
M

Mr Newbie

OK, this was not the case (AFAIK) for 2003 version, I take it that this has
changed for 2005?. And as far as my example was concerned, this is what the
designer created for me in 2003 when I dragged the label onto the design
canvass. I jsut copied and pasted it to this posting.
 
J

Jim Cheshire

Mr said:
OK, this was not the case (AFAIK) for 2003 version, I take it that
this has changed for 2005?. And as far as my example was concerned,
this is what the designer created for me in 2003 when I dragged the
label onto the design canvass. I jsut copied and pasted it to this
posting.

Yeah, it was the case with 2003.

The 2003 designer does declare it using the WithEvents keyword because there
are events defined in the class. However, this is not something you would
typically do.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry: Digging into Objects
Describes the details of digging into
memory usage with the debugger.
 
M

Mr Newbie

Thats a good point. It doesent make sense to add the withevents clause for a
label most of the time, but its probably more trouble than its worth to
remove it. Esp if you have a shed load of labels.

I wonder how much difference it would make if you had 100 labels, would it
make bringing up the page in postback slower because the withevents was used
?
 
J

Jim Cheshire

Mr said:
Thats a good point. It doesent make sense to add the withevents
clause for a label most of the time, but its probably more trouble
than its worth to remove it. Esp if you have a shed load of labels.

I wonder how much difference it would make if you had 100 labels,
would it make bringing up the page in postback slower because the
withevents was used ?

That's a good question. In fact, when you declare it with the WithEvents
keyword, the compiler will actually create the Label as a property. You can
use ILDasm to see this. The fact that you are now referencing a property
does carry a small performance hit, but you won't notice it all. It's one of
those things that MIGHT be measurable if done at an extremely large scale,
but will never be noticeable.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry: Digging into Objects
Describes the details of digging into
memory usage with the debugger.
 
M

Mr Newbie

I have a question for you.

I am writing and application which allows the author to create articles and
then the idea is they can submit it for publcation. The contents are stored
in an sql database. So far so good, but now I have the composite parts I
need to write the code to write it out to an HTML file in a subdirectory.

What pattern would you recommend to actually do the construction of the html
?
 
J

Jim Cheshire

Mr said:
I have a question for you.

I am writing and application which allows the author to create
articles and then the idea is they can submit it for publcation. The
contents are stored in an sql database. So far so good, but now I
have the composite parts I need to write the code to write it out to
an HTML file in a subdirectory.
What pattern would you recommend to actually do the construction of
the html ?

I try to avoid recommending specifics without a LOT of details on
architecture. Right off, I would wonder why you would need to actually
serialize such a thing to disk.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry: Digging into Objects
Describes the details of digging into
memory usage with the debugger.
 
M

Mr Newbie

The answer to this is simple. The serialization is to do with search
engines. In order to get the traffic you need to get spidered.

There is probably a better way to do it, but I'm not aware how!
 
J

Jim Cheshire

Mr said:
The answer to this is simple. The serialization is to do with search
engines. In order to get the traffic you need to get spidered.

There is probably a better way to do it, but I'm not aware how!

Okay. In that case, it would depend on a number of factors. Without a
detailed review, I would not want to recommend any particular approach.

--
Jim Cheshire
================================
Blog: http://blogs.msdn.com/jamesche

Latest entry: Digging into Objects
Describes the details of digging into
memory usage with the debugger.
 

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

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top