473,385 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How do I reference a second class than the codebehind page?

Hi, I have my .aspx page and its .cs codebehind page that Visual Studio
created.

What if I want to create a function or class in another .cs page but
want to use it in the codebehind page. How can I reference this new
c-sharp (or vb.net page) in the codebehind page? Thanks.

Nov 19 '05 #1
3 1213
A code behind is in fact a class and can be called

Ensure the method you are calling is public.
Ensure the method you are calling does not rely on elements on its page like
textboxes etc.

Hope this can help, haven't the time to test it, but should work

Here goes:
First page:

namespace MyNamespace
{
public class FirstPage : System.Web.UI.Page
{
public void DoSomething() //make sure public
{
//HERE IS STUFF YOU WANT TO DO FROM ANOTHER PAGE
//Like populate a database or return a string - but then would
be public string DoSomething()
}
}
}
Second page:

namespace MyNamespace
{
public class FirstPage : System.Web.UI.Page
{
private void DoSomethingFromFirstPage()
{
MyNamespace.FirstPage.DoSomething(); //don't need MyNamespace if
in same class (like this example)
}
}
}


<ne***********@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hi, I have my .aspx page and its .cs codebehind page that Visual Studio
created.

What if I want to create a function or class in another .cs page but
want to use it in the codebehind page. How can I reference this new
c-sharp (or vb.net page) in the codebehind page? Thanks.

Nov 19 '05 #2
Although you may be able to call this from another class directly, you really
should break out any of these "comon" methods into its own class and have
each page use the functions on that class.

Things such as business logic and data access are examples that really
deserve their own classes, if not their own projects and namespaces.

Hope that helps,

Jason Lind

"ne***********@gmail.com" wrote:
Hi, I have my .aspx page and its .cs codebehind page that Visual Studio
created.

What if I want to create a function or class in another .cs page but
want to use it in the codebehind page. How can I reference this new
c-sharp (or vb.net page) in the codebehind page? Thanks.

Nov 19 '05 #3
Although you may be able to call this from another class directly, you really
should break out any of these "comon" methods into its own class and have
each page use the functions on that class.

Things such as business logic and data access are examples that really
deserve their own classes, if not their own projects and namespaces.

Hope that helps,

Jason Lind

"ne***********@gmail.com" wrote:
Hi, I have my .aspx page and its .cs codebehind page that Visual Studio
created.

What if I want to create a function or class in another .cs page but
want to use it in the codebehind page. How can I reference this new
c-sharp (or vb.net page) in the codebehind page? Thanks.

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: dh | last post by:
As a simple example, I can't seem to be able to reference a label called "lblOutput" that exists in my test.aspx page from within a User control, TestControl.ascx. I am stumped. Any help is...
4
by: BH | last post by:
I'm looking at the source code of the ASP.NET forum sample application. It has the "code-behind" classes compiled into a separate DLL, totally separated from the aspx/ascx files. Adding the class...
4
by: Wayne Wengert | last post by:
I am trying to work through an ASP.NET book and in one example you build a Class and then call a method from that class in an ASPX page. I put the class file ("quote.dll") in the bin directory and...
1
by: Horace | last post by:
Hello Does anyone know how to remove (or make more general) both the Imports clause (in a class .vb file) and the Page directive (specifically the Inherits clause in a web page .aspx file). ...
2
by: Mark | last post by:
Hi, I'm fairly new to .NET and having problems getting an ASP.NET page working on my web host. The page works fine on my PC running against localhost. I have a MySQL database and a simple C#...
3
by: ABC | last post by:
How to create a web page class for inhert web page using ASP.NET 1.1 and 2.0?
8
by: PJ | last post by:
How can I get a reference to the master page class? It is defined as a partial class, but I cannot seem to type a variable to the name of the partial class? The compiler continually shows "The...
9
by: needin4mation | last post by:
I have a .aspx file and it's src. I also have a third file, a class that the src references. Everything is in the same directory/folder. Everything has the same namespace. How do I reference the...
1
by: Nathan Sokalski | last post by:
I have a UserControl that I declare programmatically as follows: Dim userctrl as New rightside_portal() The codebehind file for this UserControl looks like the following: Partial Public...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.