Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2011-03-15
3
Medium Priority
?
1,176 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 2000 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Screencast - Getting to Know the Pipeline
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

886 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