Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
647 views
in Technique[技术] by (71.8m points)

asp.net - Response.Write and UpdatePanel

I generate a vcard that I send to the client using the following code snippet:

Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", fileNameOnly));
Response.ContentType = "text/x-vcard";
Response.ContentEncoding = Encoding.GetEncoding("ISO-8859-1");
Response.Write(vCard.ToString());
Response.End();

However, I need to use vCards on a page that has the control inside and UpdatePanel. Unfortunately, according to Update panel and Response write this does not work and causes an error. I am wondering what are some alternative ways to send the contents of the vcard/file to the client's browser and have it display "open/save" dialog that don't involve Response.Write?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can't use Response.Write during an asynchronous postback. Whatever control executes that code needs to be added as a PostBackTrigger in the update panel:

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

You can also do it in code-behind, if you prefer:

ScriptManager.GetCurrent().RegisterPostBackControl(Button1);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...