带PostBackTrigger的UpdatePanel需要一个进度条/ ajax加载器

时间:2014-05-15 21:31:11

标签: c# asp.net ajax

ASPX:

    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:Button ID="btSave" runat="server" OnClick="btSave_Click" Text="Save Data" />
            <br />
            <asp:UpdateProgress ID="UpdateProgress1" runat="server" 
                AssociatedUpdatePanelID="UpdatePanel1"
                DisplayAfter="100" DynamicLayout="true">
                <ProgressTemplate>
                    <img border="0" src="loader.gif" />
                </ProgressTemplate>
            </asp:UpdateProgress>
        </ContentTemplate>
        <Triggers>
            <asp:PostBackTrigger ControlID="btSave" /> 
        </Triggers>
    </asp:UpdatePanel>

ASPX.CS

protected void btSave_Click(object sender, EventArgs e)
    {
        // Some Calculations
        btSave.Enabled = false;
        System.Threading.Thread.Sleep(900);
        btSave.Enabled = true;

        Response.Clear();
        Response.ContentType = "text/plain";
        Response.AppendHeader("content-disposition", "attachment;filename=data.txt");
        Response.WriteFile("data.txt");
        Response.End();
    }

0 个答案:

没有答案