Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 2nd, 2005, 07:54 AM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Inherits the page?

Hi!

I have made a class that I put in a include file.

I whant that class to inherits the page it is currently included on.

like this.
index.aspx
i whant
class car: inherits index_aspx

and
login.aspx
class car: inherits login_aspx

I read something about doing like this

class car: inherits system.web.UI.page
but I cant get it to work...

get this message then:

Reference to a non-shered member requiers an object reference.
when im trying to run a function from inside the class.

Tanks in forehand.

I live for scripting...
  #2 (permalink)  
Old June 2nd, 2005, 08:22 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Your terminology is a bit incorrect. The class that is dynamically compiled when the page is requested (<pagename>_aspx) is the end of the inheritance chain. You can modify what class those pages derive from, but you can't make them be inherited by another class. Those page classes are the classes that are being instantiated by the framework when you request a page.

You can create a class that inherits System.Web.UI.Page

Public Class MyPage : Inherits System.Web.UI.Page
   ...
End Class

Then your ASPX Pages can inherit your class by either direct inheritance from the page directive:

<%@ Page Inherits="MyApplication.MyPage" %>

Or by deriving the page's code-behind class from it:

<%@ Page Inherits="MyApplication.MyASPXPage" %>

Public Class MyASPXPage : Inherits MyPage
   ...
End Class

Once you have done this you can call methods in your MyPage class. If you are trying to build a class with helper functions then you don't necessarily need to make a class that is inherited by your pages. You can just build a class with shared/static methods that page code consumes.


Also, the term "include file" is not used in ASP.NET. Instead, the .vb/.cs files that you put in a project are compiled into the project assembly. Then the classes in the assembly are available for use by any executing modules in the application domain where those assemblies are found.

-Peter
  #3 (permalink)  
Old June 3rd, 2005, 03:49 AM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Im sorry, cant get it to work properly.

You say I cant use "Include file", but I am (?).

The problem is that I can use my include file everywhere (on every page) I just have to edit the inherits value to the <pagename>_aspx.

Anyway, I also tryed to use <%@ Page Inherits="MyApplication.MyPage" %>
but I dont know what myApplication is nor MyPage, so that was a big problem, and ofcurse it didnt work.

You have any Idés?

//Frej

I live for scripting...
  #4 (permalink)  
Old June 3rd, 2005, 09:26 AM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

What is this include file you are speaking of? .NET doesn't use include files like you used them in ASP. However, as I explained above, there are certain ways to have a code file that is dynamically compiled because it's referenced by the Src attribute of an ASPX file's @ Page directive. Otherwise code files (*.vb/*.cs/etc) are ignored.

"MyApplication" is the assembly root namespace. When you compile an application you typically provide a root namespace. "MyPage" is the class that is compiled into that assembly under the default namespace. Therefore the resulting fully qualified name of the class is "MyApplication.MyPage". This is the class that is inherited by the ASPX's page class.

-Peter
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VS changes Inherits automatically in ASP.NET jacob ASP.NET 1.0 and 1.1 Professional 2 December 1st, 2005 04:27 PM
Inherits Problem In Browser (Urgent) helga@trisyn.co.za ASP.NET 1.0 and 1.1 Basics 1 September 27th, 2005 09:24 AM
Inherits When Upload to ISP helga@trisyn.co.za ADO.NET 0 September 23rd, 2005 05:16 AM
Inherits sub class Brettvan1 VB.NET 2002/2003 Basics 4 June 10th, 2005 05:16 PM
Inherits error phbrady General .NET 1 April 7th, 2004 02:15 AM



All times are GMT -4. The time now is 07:45 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.