如何在静态Web方法中获取控件

Dha*_*kla 0 c# asp.net static pagemethods

我有一个[WebMethod],我想使用此代码将值分配给文本框:

[WebMethod]
public static void MyMethod(string s)
{
     //TextBox1.Text = s;   //Here how can i access the textbx?
}
Run Code Online (Sandbox Code Playgroud)

SLa*_*aks 15

你不能.

整点[WebMethod]s是它们不运行ASP.Net页面生命周期.这样,它们快速且可并行化.
您的控件不存在.

相反,您应该使用Javascript(更好)或UpdatePanel(更糟糕).