Solved

Add custom class to codebehind page..

Posted on 2006-11-02
8
187 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
Industry Leaders: 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 7

Expert Comment

by:mjmarlow
ID: 17869551
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying 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

Suggested Solutions

Title # Comments Views Activity
HTML - Color not displaying correctly in EMAIL. 6 55
abstract class C# 1 38
Need to sort columns in DataGridView 4 38
c#  FTP ftpwebrequest URI invalid 6 12
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

733 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