我正在尝试将以下 JavaScript 转换为 ASP.NET 页面的隐藏代码 (C#)。 这是 JavaScript:
function DisableButton() {
document.getElementById("<%=Submit.ClientID %>").disabled = true;
}
window.onbeforeunload = DisableButton;
我正在尝试构建一个客户端脚本,如下所示(但收到错误消息,请参阅代码后面):
StringBuilder cstext = new StringBuilder();
cstext.Append("<script type=\"text/javascript\"> function DisableButton() {");
// I get error on the following line that semi-colon is missing
cstext.Append("document.getElementById("<%=Submit.ClientID %>").disabled = true; }";
cstext.Append("window.onbeforeunload = DisableButton;");
cstext.Append("</script>");
我收到错误,提示缺少分号。我的代码需要更改什么?
最佳答案
线路
cstext.Append("document.getElementById("<%=Submit.ClientID %>").disabled = true; }";
应该是
cstext.Append("document.getElementById('" + Submit.ClientID + "').disabled = true; }");
关于javascript - 将 Javascript 转换为 ASP.NET 中的代码隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26831064/