我想显示在警报中将记录插入数据库时生成的动态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);
但没有任何事情发生,但当我删除参数时它工作正常。如何使其与参数一起使用
你有一些额外的背叛导致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_ID
和strReturnId
的实际价值。如果它们是字符串,则需要确保它们不包含引号或引号,或者您需要正确地转义这些字符。
试试这个:
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);