Wednesday, October 13, 2010

Disable Save/Open Button in ASP.NET Download Dialog box

Code Behind

protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = "application/vnd.ms-excel";
Response.AddHeader("content-disposition", "attachment;filename=sample.xls");
Response.Write("Hello World");
Response.End();
}

HTML Page

To disable Save button, write this meta tag
<head runat="server">
<meta name="DownloadOptions" content="nosave" />
</head>

To disable Open button, write this meta tag
<head runat="server">
<meta name="DownloadOptions" content="noopen" />
</head>

5 comments:

  1. The Response.End has end the response, if i click again the button, this is no post back at all.

    ReplyDelete
  2. it didnt worked for me

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete