Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2011-03-15
3
Medium Priority
?
1,165 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

715 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