Hi @Roefatin, Ridzuan,
Well, what I think you need to understand is this: when you do a download operation, the respond to browser is file, not the page. So if you want to implement such a requirement, you can try to use javascript, something like this:
<body>
<form id="form1" runat="server">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<asp:FileUpload ID="_File" runat="server" />
<asp:TextBox runat="server" ID="txtPartNo"></asp:TextBox>
<asp:Button ID="btnDownload" runat="server" Text="Download File"
OnClick="btnDownload_Click"/>
<script src="Scripts/jquery-3.4.1.min.js"></script>
<script>
$(function () {
$("#<%= btnDownload.ClientID %>").click(function () {
debugger;
$("#<%= txtPartNo.ClientID %>").val("");
});
});
</script>
</form>
</body>
And the button click event:
protected void btnDownload_Click(object sender, EventArgs e)
{
if (_File.HasFile)
{
txtPartNo.Text = null;
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + _File.FileName);
Response.AddHeader("Content-Length", _File.FileContent.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile("background.jpg");
Response.End();
//txtPartNo.Text = null;
}
}
Result:
Best regards,
Xudong Peng
If the answer is the right solution, please click "Accept Answer" and kindly upvote. If you have extra questions about this answer, please click "Comment". Note: Please follow the steps in our [documentation][1] to enable e-mail notifications if you want to receive the related email notification for this thread.