Common Function?

G

Guest

I have a common function (private void createDocument()) that I use in many
pages within my asp.net app. This function is coded into all of these
pages. What advise would you have to have this function only once in the
app and called from all applicable pages? Does it need to be in a .cs file
in the app_code folder? How would this function be called from the various
pages? I'd certainly appreciate any feedback you may have. Thank you.
 
G

Guest

Thank you. What if the createDocument() function references object on the
page like textboxes, etc.? Will this be a concern?
 
G

Guest

Thanks sloan. In my case the createDocument() function may reference
hundreds of different objects (textboxes, listboxes,etc.). Is there a way
to simply inherit from the page so I do not have to pass them as params?
 
I

Ignacio Machin ( .NET/ C# MVP )

I have a common function (private void createDocument()) that I use in many
pages within my asp.net app.  This function is coded into all of these
pages.  What advise would you have to have this function only once in the
app and called from all applicable pages?  Does it need to be in a .cs file
in the app_code folder?  How would this function be called from the various
pages?  I'd certainly appreciate any feedback you may have.  Thank you..

Hi,

How is that method accesible from all teh pages if it's declared
private?

I would create a public static method (maybe in a static class) that
receive a reference to Page (that would be the calling page) you then
would have somethig like:

page_Load( .... ){
MyStaticClass.MyStaticMethod( this);
}
 
I

Ignacio Machin ( .NET/ C# MVP )

Thank you.  What if the createDocument() function references object on the
page like textboxes, etc.?  Will this be a concern?












- Show quoted text -

Hi,

Are those controls common in all pages?
If so, make your pages to either inherit from a common page or create
an interface that declare properties to let you access those controls.
 
I

Ignacio Machin ( .NET/ C# MVP )

Thanks sloan.  In my case the createDocument() function may reference
hundreds of different objects (textboxes, listboxes,etc.).  Is there a way
to simply inherit from the page so I do not have to pass them as params?








- Show quoted text -

Whooa, hundreds of controls is not that common, maybe you should
explain with more details what is your escenario
 
G

Guest

These controls are all common within each page. Which is prefered, inherit
from a common page or create
an interface that declare properties to let you access those controls?

message
Thank you. What if the createDocument() function references object on the
page like textboxes, etc.? Will this be a concern?












- Show quoted text -

Hi,

Are those controls common in all pages?
If so, make your pages to either inherit from a common page or create
an interface that declare properties to let you access those controls.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top