Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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