[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Add custom class to codebehind page..

Posted on 2006-11-02
8
Medium Priority
?
191 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 1000 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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

656 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