Solved

ASP.NET C#: call functions from System.Web.Services.WebMethod

Posted on 2011-03-15
3
1,104 Views
Last Modified: 2012-05-11
Hello

On my web site i have declared a WebMethod on the code behind page, which I call from a JavaScript function. I have declared the WebMethod like this:

 [System.Web.Services.WebMethod]
  public static string GetKeyInfo(string ComInput, string CustomerId, string Sender, string InsertAmount)
  { 
        ----- MY CODE -----
}

Open in new window


I can call this WebMethod from the Javascript without problems and it works fine.

My problem is, that I can't call any of the other functions I have on my code behind page.

Does anyone know if it is possible to call other code behind functions from a WebMethod? And if so, how?

Regards
Søren Augustesen
0
Comment
Question by:poultarp
3 Comments
 
LVL 3

Accepted Solution

by:
ccwill88 earned 500 total points
ID: 35135555
You must move the functions in  code behind page to another class.
0
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 35135663
It can't call instance methods of the page if that is what you mean. The web method is static so there is not Page context available for it to be able to call methods that require an instance of the page. You can call other static methods though.
0
 
LVL 1

Author Closing Comment

by:poultarp
ID: 35135714
Thanks it works.

You just have to remember to declare the as static, like:

public static class ClassName
{
}

and the functions should be static as well:

public static string FunctionName()
{
}

At least that is what worked for me :o)

Regards
Søren Augustesen
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now