从asp.net中的静态方法调用非静态方法 [英] call a non-static method from a static method in asp.net
问题描述
早上好,
我编写了一个Web方法,该方法由Java脚本的页面方法调用,该Web方法在单击按钮时执行,并且由于它是静态的,因此无法调用页面控件,因此我有另一个非静态的方法来检索单选按钮.否,因为Web服务是通过Java脚本调用的,它在静态方法之前执行.我想首先获取单选按钮的值,然后将该值发送到Web服务.
Good Morning,
I have written a Web Method which is called by page method through Java script, this web method executes on button click and as it needed to be static i m not able to call the page controls thus i have another non static method to retrieve the value of radio-button. no as web service is called through Java script it executes before the static method. I want to first get the value of radio button and send the value to web service. Is it possible to call a non static method from the static method or any other way to call the web service later..?
推荐答案
Hello Gud Mrg
请改善您的问题,以便我可以提出更好的解决方案...
据我了解,在这种情况下,将您的Web方法放在.asmx文件中并从JavaScript调用方法,您无需将方法设为静态...也可以使用.asmx文件在asp.net中搜索如何使用Web方法...
让我知道是否对您有帮助....
谢谢
Nitesh Meshram
Hello Gud Mrg
Plz Improve your question so that i can put better solution...
as i understand Put your Web Method in .asmx file and call method from JavaScript in this case you have no need to make a method as Static...also search for how to Web Methods in asp.net using .asmx file...
Let me know if it is helpful to you....
Thanx
Nitesh Meshram
使用系统;
公共类MyClass {
//非静态方法.
void nonStaticMeth(){
Console.WriteLine("Inside nonStaticMeth()");
}
/*可以通过
调用非静态方法 静态方法中的对象引用. */
公共静态无效staticMeth(MyClass ob){
ob.nonStaticMeth(); //这样就可以了
}
}
using System;
public class MyClass {
// non-static method.
void nonStaticMeth() {
Console.WriteLine("Inside nonStaticMeth()");
}
/* Can call a non-static method through an
object reference from within a static method. */
public static void staticMeth(MyClass ob) {
ob.nonStaticMeth(); // this is OK
}
}
这篇关于从asp.net中的静态方法调用非静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!