在 asp.net 的警报中添加参数时 ScriptManager 不工作
ScriptManager not working while adding parameters in alert in asp.net
我想在警报中显示在数据库中插入记录时生成的动态 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);
但是什么也没有发生,但是当我删除参数时它工作正常。如何让它与参数一起工作
您有一些额外的 apos 导致 alert
损坏。假设SAP_ID
是123,strReturnId
是456,那么你构建的脚本是:
alert('Request has been created for Sap ID ='123 with Request No: '456'); window.location ='IpColoDefault.aspx';
这里多了两个apos,一个在=
之后,一个在456
之前。删除它们,您就有更好的机会真正看到警报。你想要的大概是:
alert('Request has been created for Sap ID =123 with Request No: 456'); window.location ='IpColoDefault.aspx';
当然最后的结果还要看SAP_ID
和strReturnId
的实际值。如果它们是字符串,您需要确保它们不包含 apos 或引号,或者您需要正确转义这些字符。
试试这个:
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);
我想在警报中显示在数据库中插入记录时生成的动态 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);
但是什么也没有发生,但是当我删除参数时它工作正常。如何让它与参数一起工作
您有一些额外的 apos 导致 alert
损坏。假设SAP_ID
是123,strReturnId
是456,那么你构建的脚本是:
alert('Request has been created for Sap ID ='123 with Request No: '456'); window.location ='IpColoDefault.aspx';
这里多了两个apos,一个在=
之后,一个在456
之前。删除它们,您就有更好的机会真正看到警报。你想要的大概是:
alert('Request has been created for Sap ID =123 with Request No: 456'); window.location ='IpColoDefault.aspx';
当然最后的结果还要看SAP_ID
和strReturnId
的实际值。如果它们是字符串,您需要确保它们不包含 apos 或引号,或者您需要正确转义这些字符。
试试这个:
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);