【发布时间】:2015-10-06 15:05:59
【问题描述】:
所以我有一个包含产品列表的网页。每个产品旁边都有一个超链接,用户单击该超链接可生成 Word 文档,供用户查看。每个产品都有一个 ID、尺寸等...
我有在后面的 aspx.cs 代码中执行的代码和一个 try-catch 块,用于检查所选产品是否具有尺寸。如果产品没有任何尺寸,那么我希望出现一个弹出消息框以提醒用户尚未为产品记录尺寸并且它无法生成文档。
我的问题是,我怎样才能做到这一点?我已经尝试过 Response.Write(...) 函数和 Page.ClientScript.RegisterStartupScript(...) 函数。两者都构建良好并执行但没有弹出消息。我知道我之前使用过 Response.Write() 函数,它在 VS2013 中有效,但在 VS2015 中似乎无效。
下面是我的代码。感谢您提供任何帮助/建议。
//Alert the user to fix the data if the parent sizes are missing from the Sizes column in ProductMart
try
{
//This is set to null to execute Catch block
parentSizeList = null;
pSizes = parentSizeList.Split(',');
foreach (var p in pSizes)
parentSizes.Add(p);
}
catch
{
Page.ClientScript.RegisterStartupScript(GetType(), "msgbox", "alert('TEST');", true);
Response.Write("<script type=\"text/javascript\">alert('The Measurement Sizes are missing in the Product Mart for the parent product. " +
" Please fix the data for Pack Number " + product.PackNumber + " to print inspection document');</script>");
}
【问题讨论】:
-
代码看起来不错。请检查页面源代码。你的 javascript 添加与否
-
点击超链接生成代码后做查看页面源码时好像没有添加。
-
或者,您可以在构建要显示的产品列表时检查这些尺寸值,而不是在无法创建文档的产品旁边显示链接。
-
同意。我已经考虑过了。这可能是我唯一的选择,因为我似乎仍然找不到解决方案。
标签: c# asp.net visual-studio-2015