Solved

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

Posted on 2011-03-15
3
1,115 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
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…

910 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

23 Experts available now in Live!

Get 1:1 Help Now