473,804 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1226
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.P age
{
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.P age
{
private void DoSomethingFrom FirstPage()
{
MyNamespace.Fir stPage.DoSometh ing(); //don't need MyNamespace if
in same class (like this example)
}
}
}


<ne***********@ gmail.com> wrote in message
news:11******** **************@ g14g2000cwa.goo glegroups.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
3501
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 appreciated. Thanks. The error I get when I compile is... "The type or namespace name 'lblOutput' could not be found (are you
4
7024
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 files alone in VS.NET is straightforward, but is there a way configure VS.NET to add aspx/ascx files alone?
4
1580
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 then added the aspx page that uses it to the project. When I re-open the project and right click on the aspx file and select the "Add to Project" option I get an error stating: "There is no class file associated with the WebForm 'ShowQuote.aspx'....
1
1694
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). Because we have a test and production region both residing on the same machine, each time I need to promote a change from test to production I have to change both of these references.
2
8515
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# app with an odbcConnection object, odbcDataAdapter and a datasetCustomers object placed on the form. On page load, I fill the datasetCustomers from the "Customers" table
3
1707
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
2369
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 type 'MyMaster' is not defined." I would like to reference the master page from a control, by casting the Master property of the Page property to the type, but obviously I cannot do this if I can't get a reference to the actual type. Thanks,
9
1656
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 class in my c# .src file? I don't believe this is an ASP.NET question, but a OOP C# question, thus my post here. I have searched and I thought it was with: using FilterSQL; //the name of my class using reports.FilterSQL; //name of...
1
4220
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 Class rightside_portal : Inherits System.Web.UI.UserControl Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
0
9579
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10326
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10075
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9143
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6851
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5520
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4295
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2990
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.