如何访问静态 Web 方法中的页面控件? [英] How to access page controls inside a static web method?
问题描述
我使用静态 WebMethod
方法使用 jQuery 调用了代码隐藏方法.
I have called a Code behind method using jQuery using a static WebMethod
method.
该 Web 方法调用成功,但是当尝试访问文本框控件时出现错误.非静态字段、方法或属性需要对象引用.
That web method call was success but when tried to access a text box control it is giving error. An object reference is required for the non-static field, method, or property.
[WebMethod]
public static Savedata()
{
//code to insert data to DB
//after inserting data successfully i need to change the text box text like following.
txtStatus.Text="Data Received";
}
推荐答案
正如@Tim Schmelter 所提到的,这不能回答这个问题,因为您无法从网络方法访问页面控件.
As mentioned by @Tim Schmelter This doesn't answer this question because you can't access page's controls from a webmethod.
[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.
您的问题与如何在静态网络方法中获取控件重复一个>
这篇关于如何访问静态 Web 方法中的页面控件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!