[英]Javascript function is not being called from code behind
I have a javascript function like 我有一个JavaScript函数,例如
function CloseWindow() {
alert("I am firing"); // window.close();
}
I am trying to call it from code behind button click event like 我试图从按钮单击事件后面的代码中调用它
Page.ClientScript.RegisterStartupScript([GetType](), "Javascript", "javascript:CloseWindow();", True)
The function is not firing alert message. 该功能未触发警报消息。 If I call the same function from OnClientClick it is firing.
如果我从OnClientClick调用相同的函数,则会触发。
OnClientClick="javascript:();"
What might be the cause? 可能是什么原因? If you want anymore clarification, please let me know.
如果您想进一步澄清,请告诉我。
by <script type="text/javascript" language="javascript"> function CloseWindow() { alert("I am firing"); // window.close();
} function chkLength(evt, len) { var str = document.getElementById(evt.id); if (str.value.length < len) return true; else return false; } </script>通过
<script type="text/javascript" language="javascript"> function CloseWindow() { alert("I am firing"); // window.close();
} function chkLength(evt, len) { var str = document.getElementById(evt.id); if (str.value.length < len) return true; else return false; } </script><script type="text/javascript" language="javascript"> function CloseWindow() { alert("I am firing"); // window.close();
} function chkLength(evt, len) { var str = document.getElementById(evt.id); if (str.value.length < len) return true; else return false; } </script>
If you Used Update Panels Then You can Use: 如果您使用了更新面板,则可以使用:
ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "javascriptFunction();", true);
Other Wise You can Use 您可以使用的其他明智
ClientScript.RegisterStartupScript
(GetType(),Guid.NewGuid().ToString(), "javascriptFunction();",true);
try the below code.... 尝试下面的代码...。
ClientScript.RegisterStartupScript
(GetType(),Guid.NewGuid().ToString(), "javascript: CloseWindow();",true);
The third parameter (script) must be "CloseWindow();" 第三个参数(脚本)必须为“ CloseWindow();”。 and not "javascript:CloseWindow();"
而不是“ javascript:CloseWindow();”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.