如何从vb.net代码调用javascript函数? [英] how to call javascript function from vb.net code?
问题描述
我编写了用于调用我的Javascript函数的VB.NET代码 showDisplay()
。
I have written VB.NET code for calling my Javascript function showDisplay()
.
vb.net代码:
System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "Script", "showDisplay();", True)
javascript代码:
javascript code:
function showDisplay(){
alert('success');}
但这不起作用,你能帮忙吗?
but this is not working, can you help?
推荐答案
也许你正在寻找RegisterStartupScript:
Perhaps you are looking for RegisterStartupScript:
ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "showDisplay();", True)
取决于 showDisplay()
javascript函数的存在位置您的代码,使用 RegisterClientScriptBlock
可能找不到它。这是因为 RegisterClientScriptBlock
将javascript放在页面顶部,紧跟在viewstate之后。使用 RegisterStartupScript
会将调用放在表单最底部的 showDisplay()
,这样它最后会呈现并且您的javascript函数已经呈现并可用。
Depending on where your showDisplay()
javascript function exists in your code, using RegisterClientScriptBlock
may not find it. This is because RegisterClientScriptBlock
places the javascript at the top of your page, immediately after the viewstate. Using RegisterStartupScript
will place the call to showDisplay()
at the very bottom of your form, so it will be rendered last and your javascript function will have already been rendered and available.
这篇关于如何从vb.net代码调用javascript函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!