473,395 Members | 1,468 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,395 software developers and data experts.

Reuse Method

I have many .cs code-behind files that use the same method. I have the
method coded into all of these code-behind files within the ASP.NET site.
methodName(){} Problem is when I need to change the method code I must do
so in all the code-behind files. It is a lengthy and rather complex method.
Can I add this method to a some sort of global module and simply reference
this module in all .cs files? I do not compile the code-behind files. Is
it necessary to do so? Any advice would be greatly appreciated. Thanks a
lot.

Jan 8 '08 #1
5 1739
Put the method in a class with the static modifier. All pages can see it via
MyClassName.MyMethod( <parameters);

If Web Application project, you can put the class file anywhere in the app,
if a Web Site Project, put it in the APP_CODE folder.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"msnews.microsoft.com" wrote:
I have many .cs code-behind files that use the same method. I have the
method coded into all of these code-behind files within the ASP.NET site.
methodName(){} Problem is when I need to change the method code I must do
so in all the code-behind files. It is a lengthy and rather complex method.
Can I add this method to a some sort of global module and simply reference
this module in all .cs files? I do not compile the code-behind files. Is
it necessary to do so? Any advice would be greatly appreciated. Thanks a
lot.

Jan 8 '08 #2
Thank you for the quick response, Peter. I appreciate it and will give your
suggestion a try. Thanks.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message
news:16**********************************@microsof t.com...
Put the method in a class with the static modifier. All pages can see it
via
MyClassName.MyMethod( <parameters);

If Web Application project, you can put the class file anywhere in the
app,
if a Web Site Project, put it in the APP_CODE folder.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"msnews.microsoft.com" wrote:
>I have many .cs code-behind files that use the same method. I have the
method coded into all of these code-behind files within the ASP.NET site.
methodName(){} Problem is when I need to change the method code I must
do
so in all the code-behind files. It is a lengthy and rather complex
method.
Can I add this method to a some sort of global module and simply
reference
this module in all .cs files? I do not compile the code-behind files.
Is
it necessary to do so? Any advice would be greatly appreciated. Thanks
a
lot.

Jan 8 '08 #3
Quick question, Peter. I've always been slightly confused... what is the
difference between a web application and a web site project? Aren't they the
same thing? I notice VStudio defined them differently but not sure why.

"Peter Bromberg [C# MVP]" <pb*******@yahoo.NoSpamMaam.comwrote in message
news:16**********************************@microsof t.com...
Put the method in a class with the static modifier. All pages can see it
via
MyClassName.MyMethod( <parameters);

If Web Application project, you can put the class file anywhere in the
app,
if a Web Site Project, put it in the APP_CODE folder.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com
"msnews.microsoft.com" wrote:
>I have many .cs code-behind files that use the same method. I have the
method coded into all of these code-behind files within the ASP.NET site.
methodName(){} Problem is when I need to change the method code I must
do
so in all the code-behind files. It is a lengthy and rather complex
method.
Can I add this method to a some sort of global module and simply
reference
this module in all .cs files? I do not compile the code-behind files.
Is
it necessary to do so? Any advice would be greatly appreciated. Thanks
a
lot.

Jan 8 '08 #4
Peter. Thanks for the suggestion. I gave it a shot and came up with a few
minor issues... the method references controls in the pages (all the same
controls in all the pages), however, now that the method is in the class is
can't see these controls (repeater, etc.). Also, it can't do things like
Response... or Request.QueryString... Any thought on how I might get this
working?
<msnews.microsoft.comwrote in message
news:ui**************@TK2MSFTNGP03.phx.gbl...
>I have many .cs code-behind files that use the same method. I have the
method coded into all of these code-behind files within the ASP.NET site.
methodName(){} Problem is when I need to change the method code I must do
so in all the code-behind files. It is a lengthy and rather complex
method. Can I add this method to a some sort of global module and simply
reference this module in all .cs files? I do not compile the code-behind
files. Is it necessary to do so? Any advice would be greatly appreciated.
Thanks a lot.
Jan 8 '08 #5
<msnews.microsoft.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Peter. Thanks for the suggestion. I gave it a shot and came up with a
few minor issues... the method references controls in the pages (all the
same controls in all the pages), however, now that the method is in the
class is can't see these controls (repeater, etc.). Also, it can't do
things like Response... or Request.QueryString... Any thought on how I
might get this working?
You need to pass references to whatever is required into the function. If
this is a lot of controls then possibly you're using the wrong approach. If
you have a lot of forms with the same controls then maybe you need to use a
webcontrol?
Jan 8 '08 #6

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

Similar topics

3
by: DPfan | last post by:
What's exactly the meaning of "code reuse" in C++? Why such kind of reuse have more advantages over the counterpart in other language like in C? How is "code reuse" realized in C++? By...
9
by: Charles Prince | last post by:
How do I reuse a ostrstream? So far I have replaced all code that does this "delete <ostrstream>.str()" with "<ostrstream>.freeze(0)"
3
by: danra | last post by:
Hi, I have a question which seems to me pretty basic, unfortunately I can't seem to figure it out. Let's say I have an abstract base class Vehicle and classes Car and Truck which derive from...
3
by: Giovanni Bajo | last post by:
Hello, what's the magic needed to reuse the base-class implementation of a classmethod? class A(object): @classmethod def foo(cls, a,b): # do something pass
34
by: Kovan Akrei | last post by:
Hi, I would like to know how to reuse an object of a thread (if it is possible) in Csharp? I have the following program: using System; using System.Threading; using System.Collections; ...
0
by: integragreg | last post by:
I apologize in advance if I am posting to the wrong group, but at least one of my questions is related to Platform Invoke in C#. I am using .NET Framework 1.1, and for improved performance, I...
3
by: Simon | last post by:
Hi all, I'm hoping that some of you clever chaps could offer me some advice on code reuse. You see, whenever I make applications, I typically only find very limited
5
by: apandapion | last post by:
I'm working with csharp and .net for the first time, and I've had a fair amount of luck. I started with the MSDN "Walkthrough : Creating a Distributed Application" tutorial and expanded from...
19
by: jacob navia | last post by:
There is an interesting discussion running in Slashdot now, about code reuse. The thema of the discussion is here: < quote > Susan Elliot Sim asks: "In the science fiction novel, 'A Deepness...
7
by: RichB | last post by:
I am just trying to get to grips with C# and OOP, and one of the benefits would seem to be code reuse. However I am not sure where to draw the line. I have the following section of code: if...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.