因此,我有一个包含产品列表的网页。每个产品旁边都有一个超链接,用户单击该超链接即可生成Word文档并供用户查看。每个产品都有一个ID,尺寸等...在aspx.cs文件中显示弹出消息框 - Visual Studio 2015
我的代码在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>");
}
代码看起来fine.check页面的源代码。是否已将您的javascript添加到 – shreesha
在单击超链接生成代码后,当我执行查看页面源代码时,它似乎不会被添加。 –
或者,您可以在构建要显示的产品列表时检查这些尺寸值,并且不要在无法创建文档的产品旁边显示链接。 – user2638401