Asp.Net Ajax - Call non-static method
From client side, I need to call a server method that is not static.
For example, I got the follo开发者_JAVA技巧wing user control ucData (private instance of code-behind) that is Databind in the load event.
The server method I need should return ucData.IsValid(). So it can't be static
Is there a way I can do that ?
No...because there is no instance on the server to call the method on. Once the page is generated and sent to the client, there is no more context and all instances are destroyed.
Your best option is going to be to:
- Create a static method
- Pass that method the info needed to create the instance of the object you need
- Call the method on the instance you just created
- Return the results from your static method.
精彩评论