Reuse Method

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Thank you for the quick response, Peter. I appreciate it and will give your
suggestion a try. Thanks.
 
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. 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?
 
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?
 
Back
Top