473,563 Members | 2,897 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

call a public method in aspx.cs file from another web page

I have an web page (page1.aspx) that has a method in the code behind that I want to call from another page. Is this possible to do?

The method resides in the page1.aspx.cs file, its a public method, is there a way I can call that method from another web page?

Page2.aspx.cs needs to call Public Void GetCars() in Page1.aspx.cs - is this possible?
Oct 23 '07 #1
1 9173
"Mike" <Mi**@community .nospam.comwrot e in message
news:u7******** ******@TK2MSFTN GP03.phx.gbl...
I have an web page (page1.aspx) that has a method in the code behind that
I want to
call from another page. Is this possible to do?

The method resides in the page1.aspx.cs file, its a public method, is
there a way I can
call that method from another web page?

Page2.aspx.cs needs to call Public Void GetCars() in Page1.aspx.cs - is
this possible?
It is possible - you just instantiate the class behind Page1 just as would
instantiate any other class...

However, this is almost certainly bad design...

The partial class behind an aspx page is best used for functionality which
relates specifically to that page. If you have functionality which needs to
be used by more than one aspx page, the best solution would be to take it
out of Page1.aspx.cs and place it in a separate class...
--
Mark Rae
ASP.NET MVP
http://www.markrae.net

Oct 23 '07 #2

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

Similar topics

1
1834
by: Tom | last post by:
Hi, I have an aspx file and it's cs file. I have another class cs file which execute stored procedure. In the class cs file, there are static methods. But, the button event method in aspx.cs file is not static type.
2
3037
by: moondaddy | last post by:
I'm using vb.net and have an aspx page where I want to call a function in the code behind to do something on the backend and I want to call this function from a jscript function in the aspx page. Furthermore I know there will be a postback involved but the state of the page will not change at all so I would like it to be as efficient as...
6
12265
by: grist2mill | last post by:
I want to create a standard tool bar that appears on all pages that is a control. The toolbar has a button 'New'. What I wolud like when the user clicks on 'New' depends on the page they are on. I would like to do this by defining a NewFunc() that is different in each (code-behind) page which is called by the standard 'New' button in the...
4
4210
by: Zuel | last post by:
Hi Folks. So I have a small problem. My DoPostBack function is not writen to the HTML page nor are the asp:buttons calling the DoPostBack. My Goal is to create a totaly dynamic web page where the server generates the HTML based on a passed in parameter. In our case, CustomerID. Every Customer ges a branded website with there logos and...
10
24051
by: bienwell | last post by:
Hi, I have a question about file included in ASP.NET. I have a file that includes all the Sub functions (e.g FileFunct.vb). One of the functions in this file is : Sub TestFunct(ByVal strInput As String) return (strInput & " test") End Sub
0
2939
by: Pawan Narula via DotNetMonster.com | last post by:
hi all, i'm using VB.NET and trying to code for contact management in a tree. all my contacts r saved in a text file and my C dll reads them one by one and sends to VB callback in a sync mode thread. so far so good. all contacts r added properly. now when another login adds me in his contact, i recv a subscription, so i popup a form and ask...
4
3211
by: Paul | last post by:
Hi, I've been struggling with this today, I'm developing a DotNet2.0 website in C# that needs to call a long running data query. Obviously this is a good candidate for an Asynchronous call, so the page can carry on rendering whilst the call is taking place and also returning the ASP.NET worker thread to service another page request (for...
3
3588
by: KaNos | last post by:
Hi, "robot script pages" are html+javascript pages, can be played in aspx player. So in this tech, robot call aspx player's function (an interface is sheared) and wait a result synchronously with a javascript method. I try it with GetCallbackEventReference but this tech works async. Could I use a javascript function with a sync call ?...
6
12491
by: Steve Richter | last post by:
what with the website solution structure not having a namespace, how does the class of one website .aspx page class reference the class of another page in the same website? I have two pages. _Default.aspx and Default2.aspx. How would I call a static or instance method in Default2 from _Default ? assuming the answer is to qualify with the...
0
8106
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...
1
7642
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7950
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...
0
6255
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...
0
5213
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...
0
3643
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...
0
3626
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2082
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
1
1200
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.