在asp.net下载后如何控制不能离开 [英] How control can't leave after download in asp.net

查看:70
本文介绍了在asp.net下载后如何控制不能离开的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下载图片后,我希望控件不要离开我的页面。为简单起见,请将其视为页面上的文本框。如果用户输入1,则下载特定图像并清除文本框。



protected void btnDownload_Click(object sender,EventArgs e)

{

Response.Redirect(〜/ Survey / one.png);

textbox.Text = String.Empty;

}



但是之后该控件不会停留在我的页面上,因此前面的代码表示文本框文本不能为空。

After downloading image I want the control to not leave my page. For simplicity think it as a textbox on page. If user enters 1 then a particular image is downloaded and textbox should be cleared.

protected void btnDownload_Click(object sender, EventArgs e)
{
Response.Redirect("~/Survey/one.png");
textbox.Text=String.Empty;
}

But after that control does not stay on my page so code preceding it means textbox text can't be empty.

推荐答案

您可以使用客户端代码来实现此目的。以jQuery为例。



看看这篇文章: http://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax



那里是一个jQuery插件,使下载非常简单:



You can use client-side code to achieve this. With jQuery for example.

Check out this post : http://stackoverflow.com/questions/4545311/download-a-file-by-jquery-ajax

There is a jQuery plugin that makes the download very easy:


.fileDownload('some / file.pdf')
.done(function(){alert('File download a success!');})
.fail(function(){alert('File download failed!'); });
.fileDownload('some/file.pdf') .done(function () { alert('File download a success!'); }) .fail(function () { alert('File download failed!'); });





然后你可以清除文本框





Then you can clear the textbox


('#textboxId')。val();
('#textboxId').val("");





所有这些都发生在客户端,因此用户停留在同一页面上



All this happens on the client side so the user stays on the same page


这篇关于在asp.net下载后如何控制不能离开的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆