ラベル responsewrite の投稿を表示しています。 すべての投稿を表示
ラベル responsewrite の投稿を表示しています。 すべての投稿を表示

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?

response.write and wizard

Hello!

I've been digging internet 2 days now...

Basically, i have a page with updatepanel on it. Inside, there's a wizard , with a button on the last step. This button finish the wizard - it process the whole data we have from user and it generates a file, which user should receive, with the ability to save it or open. It's easy - Response.Write. Of course it's a well known issue - ajax can't stand response.write. There are some ways to solve it , but it doesn't work for me. I've already registered it as PostbackControl, then as a AsyncControl. Added it to update's panel trigger's ( can't do it dynamically, but i did it otherwise).

Does anybody has any solution to my scenario?

I'm not sure I follow your scenario, are you trying to send the file to the user, or just data? If you're trying to get the user to be able to open/save the file, then the only way I can think of would be a redirect or transfer of the request. if it's juts data, then put a dummy asp:label in there and change its Text value.


i thought i made it clear :(

page->updatepanel->wizard->response.redirect . yes, i want to send FILE to the user.

Response.write in Update Panel

Is it possible to use a response.write in an update panel? I have a button converting a datagrid to excel using response.write. The button will work fine outside of the update panel but when I try it inside the update panel I am getting an error.

Try a response.clear

 Response.Clear() Response.AddHeader("content-disposition","attachment; filename=Survey_Results.xls") Response.Charset ="" Response.Cache.SetCacheability(HttpCacheability.NoCache)Dim stringWriterAs System.IO.StringWriter =New System.IO.StringWriter()Dim htmlWriteAs System.Web.UI.HtmlTextWriter =New HtmlTextWriter(stringWriter) stringWriter.Write("Question,Option,Option Type,Is Correct?,UserID" & vbCrLf)Dim colSurveyResultInfoAs List(Of SurveyResultInfo) = SurveyOptionController.GetSurveyResultData(ModuleId)Dim objSurveyResultInfoAs SurveyResultInfoFor Each objSurveyResultInfoIn colSurveyResultInfo stringWriter.Write(objSurveyResultInfo.Question &"," & objSurveyResultInfo.OptionName &"," & objSurveyResultInfo.OptionType &"," & objSurveyResultInfo.IsCorrect &"," & objSurveyResultInfo.UserId & vbCrLf)Next Response.Write(stringWriter.ToString()) Response.Flush() Response.Close()

After a little more research I found the answer.

<Triggers>
<asp:PostBackTrigger ControlID="btnExport" />
</Triggers>

http://ajax.asp.net/docs/mref/T_System_Web_UI_PostBackTrigger.aspx


You can't send a traditional octet stream file response in a partial postback because there isn't an HTTP response coming back to the browser. It's just a string returned to the XmlHTTPRequest.

However, you canuse an iframe to accomplish asynchronous file downloads.

Response.Write inside Updatepanel Beta 2

Hi,

I have a button inside a updatepanel, when the client click the button he can download a PDF. Everything works perfectly outside the update panel but not inside it. I got the next error message:

Sys.Webforms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error is when the response is modified by calls to Response.Write...

I really appreciate any help.

Thanks,

Jaime

My code:

PrivateSub ShowPdf(ByVal strPathAsString)

Response.ContentType =

"application/x-download"

Response.AddHeader(

"Content-Disposition","filename=YourPdf.pdf")

Response.WriteFile(strPath)

Response.End()

End Sub

<%@dotnet.itags.org.PageLanguage="VB"AutoEventWireup="false"CodeFile="Resultados.aspx.vb"Inherits="Resultados" %>

<%@dotnet.itags.org.RegisterAssembly="Microsoft.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"

Namespace="Microsoft.Web.UI"TagPrefix="asp" %>

<%

@dotnet.itags.org.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="AjaxToolKit" %>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

htmlxmlns="http://www.w3.org/1999/xhtml">

.............

<

asp:UpdatePanelID="UpdatePanel1"runat="server"><ContentTemplate><tablestyle="width: 840px"><tr><tdstyle="width: 762px; height: 153px;"><AjaxToolKit:RoundedCornersExtenderID="RoundedCornersExtender1"runat="server"TargetControlID="TitlePanel1"Radius="10"></AjaxToolKit:RoundedCornersExtender><AjaxToolKit:CollapsiblePanelExtenderID="CollapsiblePanelExtender1"runat="server"Collapsed="true"SuppressPostBack="false"TargetControlID="ContentPanel1"ExpandControlID="Panel1"CollapseControlID="Panel1"imageControlID="image1"ExpandedImage="~/images/collapse_blue.jpg"CollapsedImage="~/images/expand_blue.jpg"></AjaxToolKit:CollapsiblePanelExtender>............

<

asp:PanelID="ContentPanel1"runat="server"CssClass="collapsePanel"Height="0"Width="728px"><tablestyle="width: 728px"><tr><tdstyle="width: 93px; height: 4px"><asp:ButtonID="Button1A"runat="server"Font-Bold="True"Font-Size="X-Small"ForeColor="Crimson"Text="Get Your PDF"Width="224px"/></td>

Hi,

After a while I have found a workaround for the problem I posted, so I am posting this workaround here in case someone else have the same problem:

Basically I have include a second button (button2) outside the control panel. Once the first button (button1, the one inside the updatepanel) is clicked it fire the next javascript:

<input type="submit" name="Button1" value="Button" onclick="javascript:document.getElementById('button2').click() ;" id="Button1" /><br />

So button1 "clicks" button2 (that is the one outside the updatepanel) and this second button is the one that get the PDF file.

To include the javascript you just need to include the next line (in vb) in the "load" of the page:

button1.Attributes.Add(

"onclick","javascript:document.getElementById('button2').click() ;")

Now i am looking for a way to hidde button2 (notice that in order to click it you can not set visible to false).

Hope this can help someone.

Best,

Jaime

Response.Write with update panel issue

I am having a problem with a response.write in page.load and an atlas update panel. I created a quick sample to repro this issue. What should happen is the ddl loads with the current date. If I run it doing a response.write of the stylesheet in the page.load, it does not work. If I put the stylesheet reference at the top of the webform, it works. The page source rendered in IE is exactly the same, however using fiddler I noticed that the Atlas request on the button click returned different results. The main difference is the response.write way returns what I had in the response.write before the delta tags in the fiddler response.

In my codebehind I have:

PartialClass LiveTestInherits System.Web.UI.PageProtected Sub btnClickMe_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles btnClickMe.Click ddlStuff.Items.Add(New ListItem(Date.Now.ToString))End Sub Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.Load Response.Write("<head><link rel=""stylesheet"" type=""text/css"" href="http://links.10026.com/?link="/tools/style0.css""/></head>")End SubEnd Class
Webform
 
<%@dotnet.itags.org. Page Language="VB" AutoEventWireup="false" CodeFile="LiveTest.aspx.vb" Inherits="LiveTest" %><!--head><link rel="stylesheet" type="text/css" href="http://links.10026.com/?link=/tools/style0.css"/></head--><head runat="server"> <title>Untitled Page</title></head><atlas:ScriptManager ID="sm" runat="server" EnablePartialRendering="true"></atlas:ScriptManager><body> <form id="form1" runat="server"> <div> <div class="Heading">This is a test</div> <asp:Button ID="btnClickMe" Text="Click Me" runat="server" /> <br /> <atlas:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <asp:DropDownList ID="ddlStuff" runat="server"></asp:DropDownList> </ContentTemplate> <Triggers> <atlas:ControlEventTrigger ControlID="btnClickMe" EventName="Click" /> </Triggers> </atlas:UpdatePanel> </div> </form></body>
Fiddler Views
(Response.Write Does not work)
<head><link rel="stylesheet" type="text/css" href="/tools/style0.css"/></head><delta><rendering><head><title>....</delta>vs.(Declare stylesheet in html works)
<delta><rendering><head><title>Untitled Page</title><style type="text/css">....</delta>

Is there any kind of workaround for this issue (besides don't response.write your stylesheets)? We dynamically write out different stylesheets based on user preferences in a base page that other web pages inherit from.

Thanks in advance

I found that using

Me.Controls.AddAt(0,New System.Web.UI.LiteralControl("<head>....<style>.....</head>"))

Works fine instead of doing the response.write

Thanks