Response.Write and UpdatePanel

前端 未结 4 566
温柔的废话
温柔的废话 2020-12-06 05:51

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

Response.AddHeader(\"Content-Disposition\", string.Format(\"attachment; filena         


        
相关标签:
4条回答
  • 2020-12-06 06:24

    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);
    
    0 讨论(0)
  • 2020-12-06 06:28

    Response.Write will not work under Asynchronous Events. My suggestion is to remove the Update Panel in case it is specifically being used for VCard point of view only.

    Alternatively - Place a control inside the Update Panel and initialize it's value under asynchronous event. Now it will work.

    0 讨论(0)
  • 2020-12-06 06:29

    I had a similar problem with Response.Write. I found a workaround or maybe even a solution to this problem. Capture the TextWriter given to the RenderBeginTag of a server control and write to that.

    I blogged with an example here: http://timscyclingblog.wordpress.com/2013/03/07/asp-net-web-forms-response-write-in-an-updatepanel-dev-web/

    0 讨论(0)
  • 2020-12-06 06:31

    Why don't you consider the use of a separate handler/page to serve the vcard?

    This is maybe the easiest and cleaner way to do that and it doesnt interfere any other (async or not) postback related to the updatepanel.

    0 讨论(0)
提交回复
热议问题