Question

This is a problem I've had in the past, but I forgot if I ever solved it or not. I have it so when the user clicks on an asp:linkbutton it triggers a download for a file. File downloads successfully without a problem. However, after it downloads if the user clicks to download again or clicks a button a postback happens and the page refreshes, clearing out everything such as tables or text. How do I prevent this from happening?

Here's the code executing for the download.

string name = Path.GetFileName(filePath);
Response.Clear();
Response.AddHeader("content-disposition", "attachment; filename=\"" + name + "\"");
Response.ContentType = mimeType;
Response.BinaryWrite(file);
Response.End();

NOTES:

  • The linkbutton control is NOT created behind the scenes in code, if that makes a difference.
  • The file does not download when clicking the link on the second time. Only a refresh happens.
  • This is part of a DNN module
Was it helpful?

Solution 2

Okay, I know the source of this problem , but I never found a solution for it. The reason this even shows up is because of a setting in DotNetNuke. Under Host Settings in the Advanced Settings tab if you look at Performance Settings there is a setting called Page State Persistence. If you set this to Memory like I did it will cause AJAX issues. It's even noted in the description. Setting it back to Page makes the problem disappear.

Reason I've kept it as memory is because my company's site was using Memory, however without my knowing it was switched back to Page. Now it's a non issue, but if anyone finds a solution for when it's set to Memory let me know! Otherwise, I'd suggest against using it unless it was fixed in newer versions of DNN.

OTHER TIPS

First you need to save the information you want to keep before the post back happens. One of the ways this can be done is by using session. For example if you wanted to save the value of a text box you could say:

Session["TextBox1"] = TextBox1.Text;

Then you need to handle the post back in your page load function.

private void Page_Load()
{
   //check if this is a post back
   if(this.IsPostBack)
    {
       //restore your values
       TextBox1.Text = (string)Session["TextBox1"];
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top