且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何从vb.net代码调用javascript函数?

更新时间:2023-09-23 12:39:16

也许你正在寻找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.

推荐文章