views:

41

answers:

1

I have a link in aspx page and when i click on it,it shows a popup: open,save,cancel

but when i click cancel on that aspx page no other link works on that page.

code so far:

protected void method1()
{
            byte[] byterendered = _Filename.OpenBinary();
            Response.Clear();
            Response.ClearHeaders();
            Response.ClearContent();
            Response.ContentType = "image/jpeg";
            Response.AddHeader("Content-Disposition", "attachment;filename=abc.jpg");
            Response.CacheControl = "Public";
            Response.BinaryWrite(byterendered);
            Response.End();
}

aspx code

<asp:Linkbutton id="link1" runat="server" onClick="method1" Text="LinkA"/>
 <asp:Linkbutton id="link2" runat="server" onClick="method2" Text="LinkB" />
A: 

As the comments to your question have indicated, the reason is because your Response is being ended after the file dialog shows up. Once the response ends, any other actions on your page will not be registered. I ran into this myself while implementing a download function for my SharePoint app.

Basically, what you want to do is have your link buttons perform a window open script, instead of directly running the file transfer, like the following.

<asp:LinkButton id="link1" runat="server" onClick="window.open('TARGETURL'); return false;" Text="LinkA" />

Replace TARGETURL with an aspx page URL. Then, create a new ASPX page for the URL you specified. It will be pretty much empty, all you need are two lines.

<%@ Assembly Name="YOURFOURPARTASSEMBLYSTRINGHERE" %>
<%@ Page Language="C#" Inherits"YOURNAMESPACE.DOWNLOADCODE" %>

Replace YOURFOURPARTASSEMBLYSTRINGHERE with, of course, the four-part assembly string for your code. YOURNAMESPACE.DOWNLOADCODE will be replaced with the namespace and class that you will create for the page. The class will need to inherit the base page type, I personally used LayoutsPageBase since that's a perfect thing to use in a SharePoint app. All this class needs is an OnLoad method like the following.

// Don't actually name your class DOWNLOADCODE.
public class DOWNLOADCODE : LayoutsPageBase
{
    protected override void OnLoad(EventArgs e)
    {
        byte[] byterendered = _Filename.OpenBinary(); //More on this afterwards
        Response.Clear();    
        Response.ClearHeaders();    
        Response.ClearContent();    
        Response.ContentType = "image/jpeg";    
        Response.AddHeader("Content-Disposition", "attachment;filename=abc.jpg");    
        Response.CacheControl = "Public";    
        Response.BinaryWrite(byterendered);    
        Response.End(); 
    }
}

You will have to retrieve _Filename in this new page, of course. The best way to do this is to take whatever parameters you use to determine _Filename in the first place, and pass it as part of the URL query string.

Using this, clicking the link button will open a new window, but since all this page does it have a file response, it will just open the file dialog and be done with it. Meanwhile, your original aspx page will not have ended its response, so it can continue whatever function you need it to.

ccomet