如何访问静态Web方法中的页面控件? [英] How to access page controls inside a static web method?

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

问题描述

我已经使用静态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.

请通过 asp.net从静态函数访问控件

[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屋!

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