2017-07-31 94 views
-3

我试图在c#的页面后面添加一个javascriptasp.net代码。如何在asp.net和C#的页面后面的代码中添加javascript代码#

我发现这个网站的一些答案,我已经实现了,但我仍然无法从ScriptManager.RegisterClientScriptBlock()调用函数。

请检查我的代码;

protected void Page_Load(object sender, EventArgs e) 
{ 
    string myScriptValue = "function callMe() {alert('You pressed Me!');}"; 
    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "myScriptName", myScriptValue, true); 
} 

请帮我如何获得callMe() funtion在Page_Load()

+1

[添加客户端脚本asp.net页面动态](HTTPS的可能重复://计算器。 com/questions/1731701/add-client-script-to-asp-net-pages-dynamically) – GoldBishop

+1

你应该使用ScriptManager.RegisterStartupScript而不是ScriptManager.RegisterClientScriptBlock – Ravikumar

回答

0

你需要调用函数callMe();在ASPX因为Page_Load是第一个在网页加载JavaScript的运行之前

相关问题