How to access page controls inside a static web method?

user5061957 picture user5061957 · Jul 20, 2015 · Viewed 51.3k times · Source

I have called a Code behind method using jQuery using a static WebMethod method.

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";   
 }

Answer

AcAnanth picture AcAnanth · Jul 20, 2015

As mentioned by @Tim Schmelter This doesn't answer this question because you can't access page's controls from a webmethod.

Please go through asp.net access a control from static function

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.

your question is duplicate of How to get controls in static web method