Calling a utility function from a web page

J

Jordan

I added a C# utility class to my project. Now I would like to call that
class from a web page, but I'm not sure how to do it.

This is the new class:
public class autility : System.ComponentModel.Component
{
....
public bool Write_Log(System.Web.UI.Page Page, string strSessionLogText)
{
....

Calling code:
Write_Log (Page, "Message");

I receive the error:
The name 'Write_Log' does not exist in the class or namespace 'Project.Page'

How can I reference the function correctly?

Thanks!
 
C

Craig Deelsnyder

Jordan said:
I added a C# utility class to my project. Now I would like to call that
class from a web page, but I'm not sure how to do it.

This is the new class:
public class autility : System.ComponentModel.Component
{
...
public bool Write_Log(System.Web.UI.Page Page, string strSessionLogText)
{
...

Calling code:
Write_Log (Page, "Message");

I receive the error:
The name 'Write_Log' does not exist in the class or namespace 'Project.Page'

How can I reference the function correctly?

Thanks!

To call a method in a class as you defined it, you must create an
instance of that class and then call the method on it:

autility au = new autility();
au.Write_Log(Page,"message");

Now if you had defined it as a static method, you could have just done

autility.Write_Log(Page,"message");

but marking a method as static is not done for reducing lines of code.
There are good reasons for doing so (or not).
 

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

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,266
Latest member
DavidaAlla

Latest Threads

Top