The problem though is where is any of this going? You should be returning something to the webmethod such as a binary object that contains the file content so that it is properly formatted and structured data being returned. Here's an example of passing
files as binary objects.
This method would be fine for a web page because the web server is expecting data with a contenttype, a web service of type void is not expecting anything to be returned. The other end of the webservice call wouldn't know what to do with whatever was returned
as it's not supposed to return anything.
Don't forget to mark useful responses as Answer if they helped you towards a solution.
I don't want to return anything to the webmethod. Basically I want to click a button which will show a loading image and fire a webmethod, the webmethod will create a CSV then return to the javascript to stop the image.
Hi In order to call the method using PageMethods. First of all the method should be declared as static.
So you declared MyMethod as static and it is fine.
But you are trying to make use of Context
Context( System.Web.UI.Control.Context.get) in this case is nothing but a property that returns HttPResponse object. So it is non static so you cannot use that in static method without creating object. So you can do something like this
Member
33 Points
148 Posts
Using the Response object in a static webmethod?
Oct 10, 2011 11:40 AM|paul.wilky27|LINK
Hi all,
I'm calling a method in my code behind from javascript. I'm trying to load a CSV. Here's the code I have:
The problem is an object reference is required for the non-static field Context.Response:
Error 5 An object reference is required for the non-static field, method, or property 'System.Web.UI.Control.Context.get'
Is there any way around this?
Thanks in advance,
Wilky.
All-Star
26071 Points
5892 Posts
Re: Using the Response object in a static webmethod?
Oct 10, 2011 04:28 PM|markfitzme|LINK
The problem though is where is any of this going? You should be returning something to the webmethod such as a binary object that contains the file content so that it is properly formatted and structured data being returned. Here's an example of passing files as binary objects.
http://www.codeproject.com/KB/webservices/Transfer_any_files_on_Web.aspx
This method would be fine for a web page because the web server is expecting data with a contenttype, a web service of type void is not expecting anything to be returned. The other end of the webservice call wouldn't know what to do with whatever was returned as it's not supposed to return anything.
Member
33 Points
148 Posts
Re: Using the Response object in a static webmethod?
Oct 11, 2011 04:38 AM|paul.wilky27|LINK
Hi Mark,
I don't want to return anything to the webmethod. Basically I want to click a button which will show a loading image and fire a webmethod, the webmethod will create a CSV then return to the javascript to stop the image.
Member
10 Points
3 Posts
Re: Using the Response object in a static webmethod?
Jan 05, 2012 07:29 AM|paryasomayajulu|LINK
Hi In order to call the method using PageMethods. First of all the method should be declared as static.
So you declared MyMethod as static and it is fine.
But you are trying to make use of Context
Context( System.Web.UI.Control.Context.get) in this case is nothing but a property that returns HttPResponse object. So it is non static so you cannot use that in static method without creating object. So you can do something like this
Please visit this url https://pavanarya.wordpress.com/
Member
33 Points
148 Posts
Re: Using the Response object in a static webmethod?
May 09, 2012 05:20 AM|paul.wilky27|LINK
Hi paryasomayajulu.
I no longer work for the company I was doing this for, but I make you right in your answer.
Thanks!