Solved

Add custom class to codebehind page..

Posted on 2006-11-02
8
184 Views
Last Modified: 2010-04-16
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
0
Comment
Question by:mattisflones
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:existenz2
Comment Utility
You can alter the templates in VS2005 so that it'll automatically put the MyClass there instead of System.Web.UI.Page
0
 
LVL 7

Expert Comment

by:mjmarlow
Comment Utility
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?
0
 
LVL 15

Author Comment

by:mattisflones
Comment Utility
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..
0
 
LVL 7

Expert Comment

by:mjmarlow
Comment Utility
Can you post your attempted code?
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 15

Author Comment

by:mattisflones
Comment Utility
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..
0
 
LVL 7

Accepted Solution

by:
mjmarlow earned 250 total points
Comment Utility
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Create instance of dk_1...
        dk_1 c = new dk_1();

         // Invoke method....
         Response.Write(c.outData("test"));
    }
0
 
LVL 7

Expert Comment

by:mjmarlow
Comment Utility
0
 
LVL 15

Author Comment

by:mattisflones
Comment Utility
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.
:-)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Contant UI messages in .NET 1 40
C# Winform Button, make the border thicker and different color? 5 40
Expando 4 33
Image(7) 1 33
Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now