Script manager popup doesn't appear

核能气质少年 提交于 2020-01-06 08:48:06

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!