问题
I have an ASP.NET page. I want to throw a pop up upon clicking a certain button on the page. The syntax I used is this:
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Invalid Address!!');", true);
The popup did not appear.
However, when trying the same syntax on a different page in the same project, it worked.
Any ideas?
回答1:
Try changing the below line from
ScriptManager.RegisterStartupScript(this, this.GetType(), "popup", "alert('Invalid Address!!');", true);
to
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "popup", "alert('Invalid Address!!');", true);
If for whatever reason the above code doesn't work, try the below if it works
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "alert",
"Javascript:displayAlert('Invalid Address!!');", true);
and your JS function
function displayAlert(msg) {
alert(msg);
return false;
}
来源:https://stackoverflow.com/questions/24315618/script-manager-popup-doesnt-appear