how to call javascript function from vb.net code?

匿名 (未验证) 提交于 2019-12-03 01:20:02

问题:

I have written VB.NET code for calling my Javascript function showDisplay().

vb.net code:

System.Web.UI.ScriptManager.RegisterClientScriptBlock(Page, GetType(Page), "Script", "showDisplay();", True) 

javascript code:

function showDisplay(){ alert('success');} 

but this is not working, can you help?

回答1:

Perhaps you are looking for RegisterStartupScript:

ScriptManager.RegisterStartupScript(Me, Page.GetType, "Script", "showDisplay();", True) 

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.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!