ScriptManager not working while adding parameters in alert in asp.net

755 Views Asked by At

I want to display dynamic ID generated while inserting the record in the database in alert.

So I implemented the below mentioned code for my use.

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);

But nothing is happening, but when I removed the parameters it works fine. How to make it work with parameters

1

There are 1 best solutions below

2
user1429080 On BEST ANSWER

You have some extra apos that is causing the alert to be broken. Assuming that SAP_ID is 123 and strReturnId is 456, the script you build is:

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

There are two extra apos here, one after = and one before 456. Remove them and you have a better chance of actually seeing an alert. What you want is probably:

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

Of course the end result also depends on the actual value of the SAP_ID and strReturnId. If they are strings, you need to make sure that they don't contain apos or quotes, or you need to properly escape those chars.


Try this:

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);