473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Strange behavior by the codebehind

dw
Hello, all. I created a few Label objects, and deleted some. However, later
when I was using the codebehind page in VS .NET 2003 to set the Text of the
existing labels, I noticed that when I hit the period at the end of this"
"Me." I got the labels that had been deleted from the form's HTML. I
accidentally selected an item that was no longer on the form, and it took me
a few hours to debug that error "Object reference not set to an instance of
an object." I ultimately had to shut VS .Net down and restart it before I
even saw the new labels I had added. Hitting Refresh at the top of the
Solution Explorer didn't help.

Is this a known issue? Why am I still seeing the deleted Label objects when
I hit "Me."? Anyway to clear those items out permanently? I usually test my
pages without doing Rebuild, but by hitting F5. Could that have something to
do with it? Thanks.
Nov 18 '05 #1
7 1331
I think I've seen what you are talking about. Any time I add control in
HTML, I ALWAYS swith to the Design tab. This seems to synchronize the
codebehind (it doesn't always remove old controls though). Of course, some
people avoid the Design tab like the plague, in which case you need to add
your code-behind declarations manually.

In your codebehind, if you expand the #Region " Web Form Designer Generated
Code " section. You'll see all the current (and probably past) control
declarations you had on your form. It is safe to delete any orphaned ones.
Greg

"dw" <co***************@uncw.edu> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello, all. I created a few Label objects, and deleted some. However,
later
when I was using the codebehind page in VS .NET 2003 to set the Text of
the
existing labels, I noticed that when I hit the period at the end of this"
"Me." I got the labels that had been deleted from the form's HTML. I
accidentally selected an item that was no longer on the form, and it took
me
a few hours to debug that error "Object reference not set to an instance
of
an object." I ultimately had to shut VS .Net down and restart it before I
even saw the new labels I had added. Hitting Refresh at the top of the
Solution Explorer didn't help.

Is this a known issue? Why am I still seeing the deleted Label objects
when
I hit "Me."? Anyway to clear those items out permanently? I usually test
my
pages without doing Rebuild, but by hitting F5. Could that have something
to
do with it? Thanks.

Nov 18 '05 #2
I wouldn't call it a bug, just a limitation of what VS.Net can safely do.
In your codebehind, you'll notice a region named #Region " Web Form Designer
Generated Code ", if you expand this, you'll see all those labels you
deleted in the aspx file still declared. That's what Me. uses to show that
list...you can safely delete them.

When VS.Net adds those controls to that region, it does so 'cuz it found
them on your page, but when you remove them, vs.net can't safely remove
them..just because it isn't on the page doesn't mean you aren't dynamically
creating them in codebehind.

The new code-besides model of ASP.Net 2.0 makes these declaration dissapear,
along with the problem.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"dw" <co***************@uncw.edu> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
Hello, all. I created a few Label objects, and deleted some. However, later when I was using the codebehind page in VS .NET 2003 to set the Text of the existing labels, I noticed that when I hit the period at the end of this"
"Me." I got the labels that had been deleted from the form's HTML. I
accidentally selected an item that was no longer on the form, and it took me a few hours to debug that error "Object reference not set to an instance of an object." I ultimately had to shut VS .Net down and restart it before I
even saw the new labels I had added. Hitting Refresh at the top of the
Solution Explorer didn't help.

Is this a known issue? Why am I still seeing the deleted Label objects when I hit "Me."? Anyway to clear those items out permanently? I usually test my pages without doing Rebuild, but by hitting F5. Could that have something to do with it? Thanks.

Nov 18 '05 #3
On Mon, 6 Sep 2004 12:23:20 -0400, dw <co***************@uncw.edu> wrote:
Hello, all. I created a few Label objects, and deleted some. However,
later
when I was using the codebehind page in VS .NET 2003 to set the Text of
the
existing labels, I noticed that when I hit the period at the end of this"
"Me." I got the labels that had been deleted from the form's HTML. I
accidentally selected an item that was no longer on the form, and it
took me
a few hours to debug that error "Object reference not set to an instance
of
an object." I ultimately had to shut VS .Net down and restart it before I
even saw the new labels I had added. Hitting Refresh at the top of the
Solution Explorer didn't help.

Is this a known issue? Why am I still seeing the deleted Label objects
when
I hit "Me."? Anyway to clear those items out permanently? I usually test
my
pages without doing Rebuild, but by hitting F5. Could that have
something to
do with it? Thanks.


VS.NET does not delete those old references very well (the variable
declarations at the top of the code-behind class, sometimes they're hidden
in the auto-generated section, that's why you see them). I know for a
fact if you're going to rename a control on the aspx, do it in the Design
View, in the Properties window for that control. Otherwise the name does
not get updated on the codebehind (especially if you do it in the HTML
view).

As far as deleting, I'm not sure, but it's pry just as quirky. Try
deleting it on the Design view, not in the HTML view of the aspx. Then I
usually always switch to Design view after updating my .aspx and
double-click on the document to have VS.NET switch over to the code-behind
automatically. Seems it's then able to do things a little more cleanly,
though things you delete may still not get cleaned up as well.

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #4
WJ
"dw" <co***************@uncw.edu> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I got the labels that had been deleted from the form's HTML.


1. Make sure that you always mess around with the IDE tab, not the HTML tab.

2. Also, leave the auto generated code Region alone, do not add/modify this
region because IDE thinks that it no longer owns it and will not clean it
properly for you. I tried to trick it by adding couple of blanks and I can
repeat the problem.

3. Keep in mind that it will never get grid of "user's event/behavior" for
you, which is good, you will have to clean it yourself if you decide not to
keep the code.

John
Nov 18 '05 #5
dw
Thank you, Greg, Craig, Karl, and WJ. All make perfect sense. Yes, I was
editing the code in HTML, and so VS couldn't know of the items I'd added or
deleted. For awhile there, I thought I'd broken VS. Thanks for your help :)

"WJ" <Jo*******@HotMail.Com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
"dw" <co***************@uncw.edu> wrote in message
news:%2****************@TK2MSFTNGP14.phx.gbl...
I got the labels that had been deleted from the form's HTML.
1. Make sure that you always mess around with the IDE tab, not the HTML

tab.
2. Also, leave the auto generated code Region alone, do not add/modify this region because IDE thinks that it no longer owns it and will not clean it
properly for you. I tried to trick it by adding couple of blanks and I can
repeat the problem.

3. Keep in mind that it will never get grid of "user's event/behavior" for
you, which is good, you will have to clean it yourself if you decide not to keep the code.

John

Nov 18 '05 #6
On Mon, 6 Sep 2004 12:43:31 -0400, Karl <karl REMOVE @ REMOVE openmymind
REMOVEMETOO . ANDME net> wrote:

When VS.Net adds those controls to that region, it does so 'cuz it found
them on your page, but when you remove them, vs.net can't safely remove
them..just because it isn't on the page doesn't mean you aren't
dynamically
creating them in codebehind.

I always wondered if that was what they were really doing, but I still
considered it annoying....

Unfortunately being an OO purist, I'm not too high on the partial type
approach of 2.0 either, oh well :) I still have my business layer...

--
Craig Deelsnyder
Microsoft MVP - ASP/ASP.NET
Nov 18 '05 #7
Particularly annoying is that I cannot set the base class for my page
in code, I have to modify the Inherits attribute VS.NET sticks in the
@ Page directive....

--
Scott
http://www.OdeToCode.com

On Mon, 06 Sep 2004 12:18:21 -0500, "Craig Deelsnyder"
<cdeelsny@no_spam_4_meyahoo.com> wrote:
On Mon, 6 Sep 2004 12:43:31 -0400, Karl <karl REMOVE @ REMOVE openmymind
REMOVEMETOO . ANDME net> wrote:

When VS.Net adds those controls to that region, it does so 'cuz it found
them on your page, but when you remove them, vs.net can't safely remove
them..just because it isn't on the page doesn't mean you aren't
dynamically
creating them in codebehind.

I always wondered if that was what they were really doing, but I still
considered it annoying....

Unfortunately being an OO purist, I'm not too high on the partial type
approach of 2.0 either, oh well :) I still have my business layer...


Nov 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: | last post by:
I have a breakpoint in an aspx page that I'm using to try to trap some code to see what's going on. I'm translating a page that is working in a traditional ASP page, which takes several session...
0
by: Raed Sawalha | last post by:
Hello: I'm currently developing a web site in .net (aspx, vb.net codebehind). I have no clue why, but in all my forms (in any page), when I type text in my input fields (wether text, password or...
0
by: the friendly display name | last post by:
Hi, I have a filled multiline textbox on the site. I can scroll it with IE and Firefox, but under Opera (tested under 7.54, and Opera 8, under "identify as MSIE" and under Opera identification)...
1
by: Alexander Inochkin | last post by:
Hi! I found same strange behavior of ASP.NET. It is possible this is the bug. Follow the steps:
0
by: ivb | last post by:
Hi all, I am using DB2 8.1.11.1 on NT with ASP.NET 1.1 When application make connection to database (via ADO.NET), it set "Connection timeout" parameter to 30 seconds. After, when my webpage...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
7
by: Tim_Mac | last post by:
hi, using .net 2.0, i have a web form with lots of textboxes, drop-down-lists etc. There are lots of required field validators and regular expression validators. When i click the 'save' button,...
1
by: Nicholas Palmer | last post by:
Hi all, Got a question about the AspCompat=true page property. First a little background. We have an ASP.NET app that uses two COM components. The first is the Microsoft OWC 11 components and...
0
by: gfergo | last post by:
We have a pretty straightforward page ('Page 1'). The codebehind creates a DataTable and binds the data to a Repeater which renders an HTML table on screen. The first column in the HTML table is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.