c# - 为什么在用户控件中的一组指令后 RegisterClientScriptBlock 不起作用
问题描述
我的目标是使用一个按钮(用户控件)创建 asp.net 网络表单页面,该页面应该创建包含一些信息的 .xlsx 文件,并且在创建文件后应该发送有关成功的警报,或者警报说发生了错误。当我的方法只包含
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Record Inserted Successfully')", true);
一切正常,点击按钮后网站显示警报,但是当我像这样插入代码时
protected void createXlsx(object sender, EventArgs e)
{
using (var workbook = new XLWorkbook())
{
string a = "A";
int b = 1;
string c = String.Concat(a.ToString(), b);
var worksheet = workbook.Worksheets.Add("Sample Sheet");
worksheet.Cell(c).Value = "Id";
worksheet.Cell("B1").Value = "Imie Nazwisko";
worksheet.Cell("C1").Value = "Kwota";
worksheet.Cell("A2").Value = "";
// Prepare the response
HttpResponse httpResponse = Response;
httpResponse.Clear();
httpResponse.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
httpResponse.AddHeader("content-disposition", "attachment;filename=\"HelloWorld.xlsx\"");
// Flush the workbook to the Response.OutputStream
using (MemoryStream memoryStream = new MemoryStream())
{
workbook.SaveAs(memoryStream);
memoryStream.WriteTo(httpResponse.OutputStream);
memoryStream.Close();
}
}
ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "alertMessage", "alert('Created file succesfully')", true);
}
该站点下载 xmlx 文件,但单击按钮后不显示警报。
您对如何解决此问题或以其他方式显示消息有任何想法吗?
解决方案
推荐阅读
- django - 我应该修改什么以在 django-rest-framework 中添加新字段?
- php - 使用依赖容器的正确方法是什么?
- javascript - 如何改进特定类型的 google-autocomplete 响应?
- android - 是否可以从 MediaCodec 获得 BGR?
- javascript - 自定义创建的下拉 onclick 功能未触发
- python - 如何使用 if 子句来确保它检查问题中的“知识”词?
- erlang - 当其他模式也存在时,如何对简单的抛出进行模式匹配?
- r - 根据非 NA 列组合集合中的矩阵
- java - 春季启动中的“不支持的媒体类型” - Windows
- scala - 如何使用通用模块 Gatling3.1 生成 HMAC 签名