By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,921 Members | 1,479 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,921 IT Pros & Developers. It's quick & easy.

How to convert 1.1 code-behind page to 2.0 format?

P: n/a
Hello,

I have installed the 2.0 framework, and am looking at converting some of
my 1.1 pages to use partial classes. I don't (yet) have VS2005, so I'm
doing this by hand, but am having problems.

I have a simple page that I made in the beta2 version of VWD. The code
behind looks like...

using System;
using System.Web.UI;

public partial class _Default : Page {
protected void Page_Load(object sender, EventArgs e) {
// do stuff here
}
}

From this, I assumed that all I needed to do to my existing code-behind
files was to change the class definition to be partial, and remove the
large list of lines like...

protected Literal litTest;
// etc

from the class definition. I did this, but the compiler complained that
litTest did not exist in the current context. If I put back the above
line, it worked.

The code-behind file that VWD generated didn't have the lines in
declaring each control in the code-behind, and it worked fine. What do I
need to do to get my file to work like that? I looked in the folder
where the files live, and couldn't see any other file relating to this
page. I seem to remember that 2.0 uses a third file, which contains
extra info. Is that what I'm missing? I couldn't see one for the page
VWD created, and I could move this page to another site and it worked
fine.

Thanks for any help.

--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Anyone have an answer for this? Surely it must be a very common
question. Am I the only person trying to convert 1.1 pages to work with
2.0?
Hello,

I have installed the 2.0 framework, and am looking at converting some
of my 1.1 pages to use partial classes. I don't (yet) have VS2005, so
I'm doing this by hand, but am having problems.

I have a simple page that I made in the beta2 version of VWD. The code
behind looks like...

using System;
using System.Web.UI;

public partial class _Default : Page {
protected void Page_Load(object sender, EventArgs e) {
// do stuff here
}
}

From this, I assumed that all I needed to do to my existing code-behind
files was to change the class definition to be partial, and remove the
large list of lines like...

protected Literal litTest;
// etc

from the class definition. I did this, but the compiler complained that
litTest did not exist in the current context. If I put back the above
line, it worked.

The code-behind file that VWD generated didn't have the lines in
declaring each control in the code-behind, and it worked fine. What do
I need to do to get my file to work like that? I looked in the folder
where the files live, and couldn't see any other file relating to this
page. I seem to remember that 2.0 uses a third file, which contains
extra info. Is that what I'm missing? I couldn't see one for the page
VWD created, and I could move this page to another site and it worked fine.

Thanks for any help.


--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #2

P: n/a
Try :

using System;
using System.Web.UI;
// etc...

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// do stuff here
}

}

re:
protected Literal litTest;
// etc

That *is* needed...

See :
http://msdn.microsoft.com/asp.net/be...ta2update.aspx
and
http://msdn.microsoft.com/asp.net/re...uesasp_net.asp
and
http://msdn.microsoft.com/asp.net/re...e/default.aspx

for other critical changes going from 1.1 to 2.0

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:mE**************@nospamthankyou.spam...
Anyone have an answer for this? Surely it must be a very common question. Am I the only
person trying to convert 1.1 pages to work with 2.0?
Hello,

I have installed the 2.0 framework, and am looking at converting some of my 1.1 pages to
use partial classes. I don't (yet) have VS2005, so I'm doing this by hand, but am having
problems.

I have a simple page that I made in the beta2 version of VWD. The code behind looks
like...

using System;
using System.Web.UI;

public partial class _Default : Page {
protected void Page_Load(object sender, EventArgs e) {
// do stuff here
}
}

From this, I assumed that all I needed to do to my existing code-behind files was to
change the class definition to be partial, and remove the large list of lines like...

protected Literal litTest;
// etc

from the class definition. I did this, but the compiler complained that litTest did not
exist in the current context. If I put back the above line, it worked.

The code-behind file that VWD generated didn't have the lines in declaring each control
in the code-behind, and it worked fine. What do I need to do to get my file to work like
that? I looked in the folder where the files live, and couldn't see any other file
relating to this page. I seem to remember that 2.0 uses a third file, which contains
extra info. Is that what I'm missing? I couldn't see one for the page VWD created, and I
could move this page to another site and it worked fine.

Thanks for any help.


--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #3

P: n/a
Juan,

Thanks for the reply, but I'm still not clear!!

As far as the first bit of your post...
Try :

using System;
using System.Web.UI;
// etc...

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// do stuff here
}

}
I'm not sure what you're gaining by adding System.Web.UI.Page instead of
just Page, as the System.Web.UI namespace is already referenced at the
top of the file. Why would this make any difference?

More to the point however...
re:
protected Literal litTest;
// etc

That *is* needed...
Well, if you reread my original post, you will see that it seems it
isn't!! VWD created an .aspx and a code-behind for me, and the
"protected Literal litTest;" lines were *not* included. I copied these
two files to another web server entirely, one that has never seen VWD,
and the page ran fine.

Also...
See : <snip links>for other critical changes going from 1.1 to 2.0
I've seen most of that before, but thanks for pointing it out anyway.

Whilst looking through those links, I came across
http://msdn.microsoft.com/asp.net/re...de/default.asp
x?pull=/library/en-us/dnvs05/html/migratefromaspnetto2.asp, which shows
(just below figure 3) a new code-behind file, that does *not* have the
"protected..." lines in it.

Moreover, the text below the sample code explicitly states...

"The code-behind file has automatic access to any controls added to the
ASP.NET page"

.... which I read to support the fact that the code-behind file shown
doesn't included the references to the controls.

Hopefully you see why I didn't understand your reply. The code-behind
file that VWD generated didn't include the references, the MSDN article
seems to say that that they are not needed, but when I tried it on an
existing 1.1 file of mine, the compiler complained when I removed the
references. You say that they *are* needed. I'm confused ;-)

I would appreciate any explanation you have.

Thanks for the reply.
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:mE**************@nospamthankyou.spam...
Anyone have an answer for this? Surely it must be a very common
question. Am I the only
person trying to convert 1.1 pages to work with 2.0?
Hello,

I have installed the 2.0 framework, and am looking at converting some
of my 1.1 pages to
use partial classes. I don't (yet) have VS2005, so I'm doing this by
hand, but am having
problems.

I have a simple page that I made in the beta2 version of VWD. The
code behind looks
like...

using System;
using System.Web.UI;

public partial class _Default : Page {
protected void Page_Load(object sender, EventArgs e) {
// do stuff here
}
}

From this, I assumed that all I needed to do to my existing
code-behind files was to
change the class definition to be partial, and remove the large list
of lines like...

protected Literal litTest;
// etc

from the class definition. I did this, but the compiler complained
that litTest did not
exist in the current context. If I put back the above line, it worked.

The code-behind file that VWD generated didn't have the lines in
declaring each control
in the code-behind, and it worked fine. What do I need to do to get
my file to work like
that? I looked in the folder where the files live, and couldn't see
any other file
relating to this page. I seem to remember that 2.0 uses a third file,
which contains
extra info. Is that what I'm missing? I couldn't see one for the page
VWD created, and I
could move this page to another site and it worked fine.

Thanks for any help.


--
Alan Silver
(anything added below this line is nothing to do with me)



--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #4

P: n/a
re:
I would appreciate any explanation you have.
I short-circuited ?

It happens every so often ( even to the best among us... )

;-)

Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:z3**************@nospamthankyou.spam... Juan,

Thanks for the reply, but I'm still not clear!!

As far as the first bit of your post...
Try :

using System;
using System.Web.UI;
// etc...

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// do stuff here
}

}


I'm not sure what you're gaining by adding System.Web.UI.Page instead of just Page, as
the System.Web.UI namespace is already referenced at the top of the file. Why would this
make any difference?

More to the point however...
re:
protected Literal litTest;
// etc

That *is* needed...


Well, if you reread my original post, you will see that it seems it isn't!! VWD created
an .aspx and a code-behind for me, and the "protected Literal litTest;" lines were *not*
included. I copied these two files to another web server entirely, one that has never
seen VWD, and the page ran fine.

Also...
See :

<snip links>
for other critical changes going from 1.1 to 2.0


I've seen most of that before, but thanks for pointing it out anyway.

Whilst looking through those links, I came across
http://msdn.microsoft.com/asp.net/re...de/default.asp
x?pull=/library/en-us/dnvs05/html/migratefromaspnetto2.asp, which shows (just below
figure 3) a new code-behind file, that does *not* have the "protected..." lines in it.

Moreover, the text below the sample code explicitly states...

"The code-behind file has automatic access to any controls added to the ASP.NET page"

... which I read to support the fact that the code-behind file shown doesn't included
the references to the controls.

Hopefully you see why I didn't understand your reply. The code-behind file that VWD
generated didn't include the references, the MSDN article seems to say that that they
are not needed, but when I tried it on an existing 1.1 file of mine, the compiler
complained when I removed the references. You say that they *are* needed. I'm confused
;-)

I would appreciate any explanation you have.

Thanks for the reply.
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:mE**************@nospamthankyou.spam...
Anyone have an answer for this? Surely it must be a very common question. Am I the
only
person trying to convert 1.1 pages to work with 2.0?

Hello,

I have installed the 2.0 framework, and am looking at converting some of my 1.1 pages
to
use partial classes. I don't (yet) have VS2005, so I'm doing this by hand, but am
having
problems.

I have a simple page that I made in the beta2 version of VWD. The code behind looks
like...

using System;
using System.Web.UI;

public partial class _Default : Page {
protected void Page_Load(object sender, EventArgs e) {
// do stuff here
}
}

From this, I assumed that all I needed to do to my existing code-behind files was to
change the class definition to be partial, and remove the large list of lines like...

protected Literal litTest;
// etc

from the class definition. I did this, but the compiler complained that litTest did
not
exist in the current context. If I put back the above line, it worked.

The code-behind file that VWD generated didn't have the lines in declaring each
control
in the code-behind, and it worked fine. What do I need to do to get my file to work
like
that? I looked in the folder where the files live, and couldn't see any other file
relating to this page. I seem to remember that 2.0 uses a third file, which contains
extra info. Is that what I'm missing? I couldn't see one for the page VWD created, and
I
could move this page to another site and it worked fine.

Thanks for any help.
--
Alan Silver
(anything added below this line is nothing to do with me)



--
Alan Silver
(anything added below this line is nothing to do with me)

Nov 19 '05 #5

P: n/a
>re:
I would appreciate any explanation you have.
I short-circuited ?

It happens every so often ( even to the best among us... )

;-)


Glad to know it's not just me!!

OK, so if we agree that the control references aren't needed, are you
able to explain why I couldn't do this to an 1.1 existing page?

I changed the class declaration to be partial, and removed the list of
control declarations. That was all I could see that differentiated
between the 1.1 file I had and the 2.0 file VWD created. Oh, I also
changed the page directive of the .aspx file. When I tried to load it, I
got an exception saying a control (the first one referenced in the code)
didn't exist.

Any ideas? Thanks again
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:z3**************@nospamthankyou.spam...
Juan,

Thanks for the reply, but I'm still not clear!!

As far as the first bit of your post...
Try :

using System;
using System.Web.UI;
// etc...

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// do stuff here
}

}


I'm not sure what you're gaining by adding System.Web.UI.Page instead
of just Page, as
the System.Web.UI namespace is already referenced at the top of the
file. Why would this
make any difference?

More to the point however...
re:
protected Literal litTest;
// etc

That *is* needed...


Well, if you reread my original post, you will see that it seems it
isn't!! VWD created
an .aspx and a code-behind for me, and the "protected Literal
litTest;" lines were *not*
included. I copied these two files to another web server entirely,
one that has never
seen VWD, and the page ran fine.

Also...
See :

<snip links>
for other critical changes going from 1.1 to 2.0


I've seen most of that before, but thanks for pointing it out anyway.

Whilst looking through those links, I came across
http://msdn.microsoft.com/asp.net/re...de/default.asp
x?pull=/library/en-us/dnvs05/html/migratefromaspnetto2.asp, which
shows (just below
figure 3) a new code-behind file, that does *not* have the
"protected..." lines in it.

Moreover, the text below the sample code explicitly states...

"The code-behind file has automatic access to any controls added to
the ASP.NET page"

... which I read to support the fact that the code-behind file shown
doesn't included
the references to the controls.

Hopefully you see why I didn't understand your reply. The code-behind
file that VWD
generated didn't include the references, the MSDN article seems to
say that that they
are not needed, but when I tried it on an existing 1.1 file of mine,
the compiler
complained when I removed the references. You say that they *are*
needed. I'm confused
;-)

I would appreciate any explanation you have.

Thanks for the reply.
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ : http://asp.net.do/faq/
ASPNETFAQ.COM : http://www.aspnetfaq.com/
Foros de ASP.NET en Español : http://asp.net.do/foros/
======================================
"Alan Silver" <al*********@nospam.thanx> wrote in message
news:mE**************@nospamthankyou.spam...
Anyone have an answer for this? Surely it must be a very common
question. Am I the
only
person trying to convert 1.1 pages to work with 2.0?

>Hello,
>
>I have installed the 2.0 framework, and am looking at converting
>some of my 1.1 pages
>to
>use partial classes. I don't (yet) have VS2005, so I'm doing this
>hand, but am
>having
>problems.
>
>I have a simple page that I made in the beta2 version of VWD. The
>code behind looks
>like...
>
>using System;
>using System.Web.UI;
>
>public partial class _Default : Page {
> protected void Page_Load(object sender, EventArgs e) {
> // do stuff here
> }
>}
>
>From this, I assumed that all I needed to do to my existing
>code-behind files was to
>change the class definition to be partial, and remove the large
>list of lines like...
>
>protected Literal litTest;
>// etc
>
>from the class definition. I did this, but the compiler complained
>that litTest did
>not
>exist in the current context. If I put back the above line, it worked.
>
>The code-behind file that VWD generated didn't have the lines in
>declaring each
>control
>in the code-behind, and it worked fine. What do I need to do to get
>my file to work
>like
>that? I looked in the folder where the files live, and couldn't see
>other file
>relating to this page. I seem to remember that 2.0 uses a third
>file, which contains
>extra info. Is that what I'm missing? I couldn't see one for the
>page VWD created, and
>I
>could move this page to another site and it worked fine.
>
>Thanks for any help.
>

--
Alan Silver
(anything added below this line is nothing to do with me)


--
Alan Silver
(anything added below this line is nothing to do with me)



--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #6

P: n/a
The protected control references are not needed in the codebehind page
as the aspx file and the codebehind file sine asp.net combines these 2
classes into 1 class. This is what partial class brings to the table in
..NET 2.0.

In the @page directive there will be an attribute called Inherits which
sholud point to your _Default class and another attribute called
CodeFile which VWD usues to link both files in the designer.

As far as your error goes. It would be good to see what your aspx file
looks like since your codebehind file seems to be ok.

Nov 19 '05 #7

P: n/a
<Plays theme from Twilight Zone>

Well, I don't know what I did differently now from the other day, but I
just tried it again and it worked fine!!

I wonder if I didn't change the Src attribute of the page directive to
CodeFile? Rereading my original post, I didn't mention doing that, so it
could be I missed that change.

Anyway, all seems to be working now. Thanks very much for your reply.
The protected control references are not needed in the codebehind page
as the aspx file and the codebehind file sine asp.net combines these 2
classes into 1 class. This is what partial class brings to the table in
.NET 2.0.

In the @page directive there will be an attribute called Inherits which
sholud point to your _Default class and another attribute called
CodeFile which VWD usues to link both files in the designer.

As far as your error goes. It would be good to see what your aspx file
looks like since your codebehind file seems to be ok.


--
Alan Silver
(anything added below this line is nothing to do with me)
Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.