Solved

Add custom class to codebehind page..

Posted on 2006-11-02
8
188 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 14

Expert Comment

by:existenz2
ID: 17864886
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
ID: 17865337
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
ID: 17866451
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 7

Expert Comment

by:mjmarlow
ID: 17867434
Can you post your attempted code?
0
 
LVL 15

Author Comment

by:mattisflones
ID: 17868115
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
ID: 17869470
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 15

Author Comment

by:mattisflones
ID: 17869667
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

726 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