Link to home
Start Free TrialLog in
Avatar of mattisflones
mattisflonesFlag for United States of America

asked on

Add custom class to codebehind page..

Hi..

I have untill now just used a single custom class where i just edited the standard cs file like this:
public partial class Admin_users : MyClass

And moved "System.Web.UI.Page" to that MyClass cs file..

But how do i utilize custom classes in my codebehinc file without doing the above?
Can i add more than one class to a page?

Wht did i miss? ;-P
Avatar of existenz2
existenz2
Flag of Netherlands image

You can alter the templates in VS2005 so that it'll automatically put the MyClass there instead of System.Web.UI.Page
If you are asking
Can the codebehind partial class derive from more than one class?  
The answer is no.  C# does not allow multiple inheritance.

If you are asking
How do i use other custom classes in my code behind?
You would use them the same way in any other C# class.  Construct an instance or access static object within your classes.

Does this help?
Avatar of mattisflones

ASKER

mjmarlow, its starting to help!

#1: Ok, fine.. :-)

2#: Sounds like what i want..
How do i do that? Ive tried using a "using myClass;", but VS compalin about namespaces and types..
Can you post your attempted code?
My custom class:
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


/// <summary>
/// Summary description for dk_1
/// </summary>
public class dk_1
{
      public dk_1()
      {
            //
            // TODO: Add constructor logic here
            //
      }
    public string outData(string inn)
    {
        string tempStr = string.Empty;
        if (inn.ToString() != "")
            tempStr = inn;
        else
            tempStr = "No input";

        return tempStr;
    }
}
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤


And my test.aspx.sc
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Data.SqlClient;
using System.Collections.Generic;

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

         Response.Write(outData("test"));
    }
¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

As you can see.. its all standard... my problem is that i do not know how to add/access my class..
ASKER CERTIFIED SOLUTION
Avatar of mjmarlow
mjmarlow
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mjmarlow, Thanks a bunch.. You have opened my eyes!

I have thought about that book before, and will buy it now..
I do believe i have some gaps in my knowledge.
:-)