I am working with Visual Studio .NET, I know that the environment creates a code behind class that inherits from the System.Web.UI.Page class.
Nevertheless, I want to create my own code behind class that I will insert between the Page class and the code behind class generated from the ASPX file. which will help me to provide common fonctionality for my ASP pages.
The inheritance hierarchy is the floowing :
ASP_Page inherits MyCodeBehind which in turns inherits the Page class. It is how I assume that it should work. But I tried to do it and it never worked, is there anyone here who could explain me how to do or point me to valuable information or exemple?
Thanks in advance
The way you've described it should be fine. If it's not working, you might just have a bit of the inheritance code wrong.
My ASP.NET pages use an intermediate class of the type you've described. So, here is the hierarchy of my classes:
First, my xPage class inherits from System.Web.UI.Page:Namespace e3.Web.UI
Public Class xPage
' code here to that overrides some standard Page methods
Then, my codebehind class I call my iPage class, which inherits from the xPage class above:Namespace e3.Web.UI
Public Class iPage
' code-behind code here
Then, my WebForm (the ASPX page), inherits the above iPage class:<%@ Page Language="VB" Debug="True" Inherits="e3.Web.UI.iPage" autoeventwireup="False" %>
Does that help to show the hierarchy and how each class inherits the last?
I still have problems.
First remark when I use Visual Studio .NET , if my ASPX page is WebForm2.aspx, the environment create automatically a code behind file named WebForm2.aspx.cs.
Nevertheless when I set in my page the following,
<%@ Page Language="C#" Inherits="WebApplication1.Page2" Src="Page2.cs" AutoEventWireUp="false" Debug="true" %>
Then when the ASPX page is parsed in a class, I see the following :
public class WebForm2_aspx : WebApplication1.Page2
Which means that the WebForm2.aspx.cs created by Visual Studi is still there but is by passed. Not very clean as there should not be no WebForm2.aspx.cs but fair enough.
My problem is when I try to access my pagefor the first time, the ASPX page tries to get compiled but I get the following compilation error :
Compiler Error Message: CS1595: 'WebApplication1.Page2' is defined in multiple places; using definition from 'c:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files\webapplication1\8dd84b00\b065eec7\assembly\dl2\a646d895\00cb2915_01a8c301\WebApplication1.DLL'
I reset IIS and delete the ASP.NET cache files located at "C:\WINNT\Microsoft.NET\Framework\v1.1.4322\Temporary ASP.NET Files" but it does not help.
Anyone got a clue on this issue?
thank you in advance,