因此,我有一個包含產品列表的網頁。每個產品旁邊都有一個超鏈接,用戶單擊該超鏈接即可生成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