在asp.net中的alert中添加参数时,ScriptManager无法正常工作

问题描述 投票:0回答:1

我想显示在警报中将记录插入数据库时​​生成的动态ID。

所以我实现了下面提到的代码供我使用。

ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Request has been created for Sap ID ='" + ObjIPColoFields.SAP_ID + " with Request No: '" + strReturnId + "'); window.location ='IpColoDefault.aspx';", true);

但没有任何事情发生,但当我删除参数时它工作正常。如何使其与参数一起使用

c# asp.net scriptmanager
1个回答
1
投票

你有一些额外的背叛导致alert被打破。假设SAP_ID是123而strReturnId是456,那么你构建的脚本是:

alert('Request has been created for Sap ID ='123 with Request No: '456'); window.location ='IpColoDefault.aspx';

这里有两个额外的,一个在=之后,一个在456之前。删除它们,你有更好的机会实际看到警报。你想要的可能是:

alert('Request has been created for Sap ID =123 with Request No: 456'); window.location ='IpColoDefault.aspx';

当然,最终结果还取决于SAP_IDstrReturnId的实际价值。如果它们是字符串,则需要确保它们不包含引号或引号,或者您需要正确地转义这些字符。


试试这个:

ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Request has been created for Sap ID = " + ObjIPColoFields.SAP_ID + " with Request No: " + strReturnId + "'); window.location ='IpColoDefault.aspx';", true);
© www.soinside.com 2019 - 2024. All rights reserved.