[CLOSED] Download button

  1. #1

    [CLOSED] Download button

    Hi there,

    I don't mean to ressurect any old threads but basically we're having the same problem as Timothy had almost a year ago. Which was supposed to be fixed but for some reason it's not working for us. We're using Ext.NET 1.0.3901.23520 (revision 3042)

    http://forums.ext.net/showthread.php...D-Button-Click


    What it boils down to is, in Internet Explorer, sites in every zone except Local Intranet display a 'download warning' when it thinks something fishy is going on. Clicking on a <button> element does not constitute as fishy, but a postback trigged through an JS event listener on some divs (like Coolite is doing) does. So basically we would like to know if it's possible to have Ext.Net use <button> html elements for Buttons, or some way to use a 'classic' ASP.Net button inside an Ext.Net layout.

    We can whip up test cases if need be. Thanks very much
    Last edited by Daniil; Sep 24, 2010 at 11:49 AM. Reason: [CLOSED]
  2. #2
    Hi,

    Fixed. Please update from SVN (don't forget to set AutoPostBack="true" for the button)
  3. #3

    Doesn't work for me

    Sorry to be replying so late but it doesn't seem to be solved at all here.

    I just updated from SVN, using version 1.0.3930.20134 (rev 3141). I can provide a test case:

    
    <%@ Page Language="C#" AutoEventWireup="true" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
    </head>
    <body>
    	<form id="form1" runat="server">
    		<script type="text/C#" runat="server">
    
    			protected void OnClick(object sender, EventArgs e)
    			{
    				var bytes = new UTF8Encoding().GetBytes("Hello World");
    				WriteBytes(bytes, "text/plain", "somefile.txt");
    			}
    				
    			/// <summary> Write the specified bytearray to the user as a file </summary>
    			/// <param name="data">Bytedata to write</param>
    			/// <param name="mimeType">Mimetype of the file</param>
    			/// <param name="fileName">(display)name of the file</param>
    			private static void WriteBytes(byte[] data, string mimeType, string fileName)
    			{
    				HttpResponse response = HttpContext.Current.Response;
    
    				response.Clear();
    				response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", fileName));
    				response.AddHeader("Content-Length", data.Length.ToString());
    				response.ContentType = mimeType;
    				response.BinaryWrite(data);
    				response.End();
    			}
    		</script>
    		<ext:ResourceManager runat="server" />
    		<ext:Button Text="Download!" runat="server" OnClick="OnClick" AutoPostBack="true" />
    	</form>
    </body>
    </html>
    Running IE7 (and I believe 8 too) in Internet zone will yield the error. To trick my browser into thinking I wasn't using my local IIS I had to adjust my hosts file.
    Attached Files
  4. #4
    Hi,

    Yes, our fix doesn't work with your sample. As you understood it is IE security warning and it is dificult to prevent it.
    I can suggest to use the following workaround
    <%@ Page Language="C#" AutoEventWireup="true" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title></title>
        
        <script runat="server">
     
                protected void OnClick(object sender, EventArgs e)
                {
                    var bytes = new UTF8Encoding().GetBytes("Hello World");
                    WriteBytes(bytes, "text/plain", "somefile.txt");
                }
                     
                private static void WriteBytes(byte[] data, string mimeType, string fileName)
                {
                    HttpResponse response = HttpContext.Current.Response;
     
                    response.Clear();
                    response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", fileName));
                    response.AddHeader("Content-Length", data.Length.ToString());
                    response.ContentType = mimeType;
                    response.BinaryWrite(data);
                    response.End();
                }
            </script>
    </head>
    <body>
        <form id="form1" runat="server">        
            <ext:ResourceManager runat="server" />
            <ext:Button Text="Download!" runat="server" AutoPostBack="true" OnClick="OnClick">
                <Listeners>
                    <Click Handler="if(Ext.isIE){Ext.getDom('Button1').click(); return false;}" />
                </Listeners>
            </ext:Button>
            <asp:Button ID="Button1" runat="server" OnClick="OnClick" style="display:none;"/>
        </form>
    </body>
    </html>
  5. #5
    Unbelievable. Some security that is.
    Thanks guys, you helped me out a lot.

Similar Threads

  1. [CLOSED] How can I download 2.x?
    By ducnt in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Feb 13, 2012, 8:05 PM
  2. [CLOSED] [1.0] MVC Download file
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Aug 02, 2010, 11:10 AM
  3. Replies: 3
    Last Post: Feb 02, 2010, 6:32 PM
  4. [CLOSED] [1.0] File download in MVC
    By tdracz in forum 1.x Legacy Premium Help
    Replies: 2
    Last Post: Nov 23, 2009, 4:43 PM
  5. [CLOSED] ux toolkit download
    By fabiomarcos in forum 1.x Help
    Replies: 2
    Last Post: Dec 04, 2008, 3:11 PM

Posting Permissions