i'm writing a website using .NET 1.1 and C#, but I've come across I few really annoying snags, I just wondered if anybody else had?
Right, I have two class, both in seperate .aspx files, both classes inherit from System.Web.UI.Page and each of them can contain public classes inside of those classes.
Now if I wanted to use the class from fileA, inside fileB - how on earth can I do this? I don't really want to pre-compile everything I write into a library.dll file just for the sake of some inheritance and I don't think putting the classes into .CS files will work either ...
is there anyway around this? I could kind of guess why it is designed like this, but it seems a massive oversight and a missed oppotunity in the C# language and for website development - am I missing something?
any suggestions greatfully received ...
C# - Object Inheritance? (Web Dev.)
C# - Object Inheritance? (Web Dev.)
01000101 01000100 01000111 01000101
http://www.redbubble.com/people/fotofill/ buy my photos!
Re: C# - Object Inheritance? (Web Dev.)
If you're wanting both aspx pages to be able to share the same functionality, you can try a couple of things:moosedude wrote:i'm writing a website using .NET 1.1 and C#, but I've come across I few really annoying snags, I just wondered if anybody else had?
Right, I have two class, both in seperate .aspx files, both classes inherit from System.Web.UI.Page and each of them can contain public classes inside of those classes.
Now if I wanted to use the class from fileA, inside fileB - how on earth can I do this? I don't really want to pre-compile everything I write into a library.dll file just for the sake of some inheritance and I don't think putting the classes into .CS files will work either ...
is there anyway around this? I could kind of guess why it is designed like this, but it seems a massive oversight and a missed oppotunity in the C# language and for website development - am I missing something?
any suggestions greatfully received ...
1. Create your own class that inherits from System.Web.UI.Page, and add whatever functionality you'd like. Then have you aspx pages inherit from "MyPage" versus System.Web.UI.Page.
2. Create a seperate CS file, and assign it a namespace. Then you should be able to reference that namespace in your aspx files and access those additional functions / objects.
Hope that helps, if not lemme know.
-Chris B.
Thanks for your suggestion, in the end I just put the classes I needed into a pre-compiled library.
anyway, I not sure what you meant in (2), of your suggestions, would you mind explaining in a bit more detail please?
I guess what I wanted to do was simular to C++'s #include statement, where I have the freedom to reference any code file I want and inherit from the classes within.
My aspx standard template is to create a aspx file with a codebehind attribute at the top to reference a .cs file. I would use the aspx file for the GUI, and the .cs file for the functionality. This setups ok, but I still want to reference more than one file in this codebehind statement ..?
I already have a "master page" class, from which all pages inherit from, which is actually a cracking idea and makes life easier in the long run...
anyway, I not sure what you meant in (2), of your suggestions, would you mind explaining in a bit more detail please?
I guess what I wanted to do was simular to C++'s #include statement, where I have the freedom to reference any code file I want and inherit from the classes within.
My aspx standard template is to create a aspx file with a codebehind attribute at the top to reference a .cs file. I would use the aspx file for the GUI, and the .cs file for the functionality. This setups ok, but I still want to reference more than one file in this codebehind statement ..?
I already have a "master page" class, from which all pages inherit from, which is actually a cracking idea and makes life easier in the long run...
01000101 01000100 01000111 01000101
http://www.redbubble.com/people/fotofill/ buy my photos!
Sure, what I'm talking about is this: (for example)moosedude wrote:anyway, I not sure what you meant in (2), of your suggestions, would you mind explaining in a bit more detail please?
-- Math.cs --
Code: Select all
namespace MathFunctions
{
public class Math
{
public Math()
{
}
static public int Add(int x, int y)
{
return x + y;
}
}
}
Code: Select all
using MathFunctions;
...
private void Page_Load(object sender, System.EventArgs e)
{
txtAnswer.Text = Math.Add(10, 2).ToString();
}
-Chris B.

