如何在静态 Web 方法中获取控件 [英] How to get controls in static web method

查看:17
本文介绍了如何在静态 Web 方法中获取控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 [WebMethod] 并且我想使用以下代码为文本框赋值:

I have a [WebMethod] and i want to assign values to a text box using the this code:

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

推荐答案

你不能.

[WebMethod] 的全部意义在于它们不运行 ASP.Net 页面生命周期.这样,它们既快速又可并行.
您的控件不存在.

The whole point of [WebMethod]s is that they don't run the ASP.Net page lifecycle. This way, they're fast and parallelizable.
Your controls don't exist.

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

Instead, you should use Javascript (better) or an UpdatePanel (worse).

这篇关于如何在静态 Web 方法中获取控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆