从ASP.net代码后面调用JavaScript函数 [英] Call JavaScript function from ASP.net code behind
本文介绍了从ASP.net代码后面调用JavaScript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从后面的代码中调用JavaScript函数,但到目前为止还算不上成功.我试图在 Page_Load
方法内添加以下代码段.
I’m trying to call a JavaScript function from Code behind but no luck so far. I tried to add the following snippets inside Page_Load
method.
我尝试了以下方法
ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "foo", "alert('test22222')", true);
也如下
Page.ClientScript.RegisterStartupScript(Type.GetType("System.String"), "addScript", "alert('test22222');", true);
没有人为我工作.我在这里想念什么吗?我想在加载页面之前显示警报消息.
None worked for me. Is there anything I’m missing here? I would like to show the alert message before loading the page.
任何帮助表示赞赏.谢谢.
Any help appreciated. Thanks.
推荐答案
您可以在page_prerender事件中实现它
you can implement it in page_prerender event
protected void page_prerender( object sender, EventArgs e )
{
your code here;
}
这篇关于从ASP.net代码后面调用JavaScript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文