2012年3月26日月曜日

response.write and ajax problem

how can i use response.write with ajax?

i made a project and diceded to add ajax to it

but it uses response.write to return <%functionname()%>

but i get an error when i do this and i looked around and found that ajax has a problem with response.write

is there a way around it?

P.S my error :

"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be

paresed. Common causes for this error are when response is modified by calls to Response.Write(),response

filters, HttpModules, or server trace is enabled."

i get this when i postback(first load kk but (i use alot of response.write in the ajaxpanel controls and outside(non ajax controls witch get there vaules from <%myfunction()%> but these values don't change when an ajaxpanle controls post)

anything i can do?

P.S pressing the button works , it's the response that ajax can't understand (when i press the ajax button (witch updates a static int) i get an error but when i press any normal control (and get postback) i get the new static int , so the ajax controled posted.

thanks

Don't know if this is going to answer all your questions, however I had no problem with Ajax and Response.Write ... yet, however won't update if you don't ad a UpdatePanel. Also trace and ajax work together but you may see some div problems between the trace data and the web form when it renders.

Hope this helps a little


hello.

you shouldn't use response.write in ajax page.

i always use response.write (forgot all othere)

is there any othere way to return stuff throw <%myfunc()%> that ajax can handle?

return dosn't seen to wrok

and can u show mw how did u use response.write with ajax and it worked?

thanks


hello again.
well, response.write was the way to go in old asp. asp.net has a great object model so you should work with it instead of using response.write.

you shouldn't use response.write because it just inserts what you're doing on the page where you put it. this might break the the predefined ajax message that is returned from the server to the client.

i'm not sure on what you're trying to do...i'm assuming that myfuc() is a server side method and you want to put its result in the contents that are retrurned to the client. for instance, if you're putting it on a label, you can do something like this (during the load event, for example):

mylabel.Text = func();
Ok, don't use Response.Write for everything, is good for injecting scripts, but otherwise just update the controls, using controls handles is the way to go.

hello.

for injecting scripts you should use the registerXXX methods of the scriptmanager class...


I cannot find another method to solve this problem. I have a button, pressing this, in server I'll check some conditionals, if right, I'll change some text at other places in client that not stored in UpdatePanel (I cannot use so much UpdatePanel cos may be I have to change data in many place, UpdatePanel = Load fully a page)

Or another example, after checking at server, this page should be close and the opener page should be refresh. How can I do if I dont use Response.write (but using updatepanel, response.write is not active)

Thank guards.


Hi there.


I also came across a similar issue and was wondering if you had any insight/suggestions.


I would like to force a file download from code, and on a non-ajax page the following works file, but not when nested in a grid view. Here is the code:


string sFileName = "Foobar.html";
string sHTML = "foo 123";

Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + sFileName);
Response.AddHeader("Content-Length", sHTML.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.Write(sHTML);
Response.End();

Any suggestions on how to accomplish this without Response.Write?

0 件のコメント:

コメントを投稿