how to change this code to ASP.NET 2 ?

  • Thread starter Thread starter Tee
  • Start date Start date
T

Tee

in ASP.NET 1.1,

I created a Class, and the class Inherits System.Web.UI.Page ...

I write my common error handling code there, under Protected Overrides Sub
OnError(ByVal e As System.EventArgs)

and all my ASPX inherits the class with no problem.


But in ASP.NET 2, how can I do the same ?

I can't get my ASPX file to inherits any other thing beside
System.Web.UI.Page ...

anyone know how ?


Thanks,
Tee
 
Hi,

in ASP.NET 2 the code-behind(beside) class is one and the same class with
the dynamically created page class as they use the new partial class feature
of the Framework 2. It also means that the Page inherits implicitly from
System.Web.UI.Page.

This is error what I get when trying to have another base class:

Base class 'MyDemoClass' specified for class 'Default_aspx' cannot be
different from the base class 'System.Web.UI.Page' of one of its other
partial types.

You can do it by handling the error in global.asax.
 
Hi,

So do you meant I have to re-structure my code in order for it to work in
ASP.NET 2 caused of there is no other way can replace it ?

Then why is .Net Framework saying Backward Compatibility ?


Thanks,
Tee
 
Well,

remember that this is only the first beta so its not final (neither is the
compatibility). In practise there will probably be tradeoffs and the
backwards compatibility won't be perfect even though MS tries their best
with it. It is just the goal.

You might also have a look at ASp.NET 2.0 forums at ASp.NET Forums
(www.asp.net/forums)

See also these interesting threads:
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=612882
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=622319
http://www.asp.net/Forums/ShowPost.aspx?tabindex=1&PostID=627529
 
Hi Teemu,

Thanks for your reply to few of my post here.

After spending sometimes in ASP.NET 2, I found that we still can inherits
another class. But we need to do this in the html source <%@ Page .....%>.

eg:
<%@ Page Inherits="Class1" Language="C#" CompileWith="Default2.aspx.cs"
ClassName="Default2_aspx" MasterPageFile="~/MasterPage.master" %>


the class to inherits must have inherited to System.Web.UI.Page or else it
will give error.


Thanks,
Tee
 
Yeah, that was mentioned in one of the links I gave (runtime supports but
tools don't)
 
I had a recent post about this very issue:
http://odetocode.com/Blogs/scott/archive/2004/06/24/286.aspx

I hope the tools will change to allow us to specify the base class in
code instead of the @Page declaration, it makes more sense that way, I
feel.

The post also addresses another issue we used to run into, which is
having an abstract class in the Page inheritance hierarchy used to
choke the VS.NET designer, but this appears to work now.
 

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

Back
Top