简体   繁体   English

从vb.net后面的代码调用javascript

[英]calling javascript from code behind vb.net

What I'm trying to do is to use javascript function to autoclick a button as method for error handling. 我想要做的是使用javascript函数自动点击按钮作为错误处理的方法。 The javascript work just fine with onClick on the button .The problem that I faced is that the javascript called does not work at all when I called it from the code behind. 使用onClick按钮时javascript工作正常。我遇到的问题是,当我从后面的代码中调用它时,调用的javascript根本不起作用。 Am I doing it wrong? 我做错了吗?

here is my javascript: 这是我的javascript:

<script type="text/javascript">
function callbtn() {
    document.getElementById("btnAlert").click();
}
 </script>

and here is the method that I used to call javascript from code behind: 这是我用来从后面的代码调用javascript的方法:

If CheckLotIDExist = "Y" Then
 'do something here
Else
    LblMsg.Text = "Lot Not Foundzz!"
   ScriptManager.RegisterStartupScript(Page, Page.GetType, "script", "callbtn();", True)
End If

Try this: 尝试这个:

 const string script = "function f(){callbtn(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
 ScriptManager.RegisterStartupScript(Page, Page.GetType(), "keyLicDtlz", script, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM