2017-07-31 157 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的運行之前

相關問題