Response.Write和UpdatePanel

lac*_*dev 13 asp.net updatepanel response.write httpresponse

我使用以下代码片段生成一个我发送给客户端的vcard:

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();
Run Code Online (Sandbox Code Playgroud)

但是,我需要在内部具有控件和UpdatePanel的页面上使用vCards.不幸的是,根据更新面板和响应写入, 这不起作用并导致错误.我想知道什么是将vcard /文件的内容发送到客户端浏览器的其他方法,并让它显示"打开/保存"对话框,不涉及Response.Write?

Jam*_*son 38

您不能Response.Write在异步回发期间使用.无论执行什么控件,都需要PostBackTrigger在更新面板中添加代码:

<Triggers>        
    <asp:PostBackTrigger ControlID="Button1" />
</Triggers>
Run Code Online (Sandbox Code Playgroud)

如果您愿意,也可以在代码隐藏中执行此操作:

ScriptManager.GetCurrent().RegisterPostBackControl(Button1);
Run Code Online (Sandbox Code Playgroud)