我以前使用過這樣的代碼,可以在我的asp.net網頁上成功彈出警告消息。現在它不工作。我無法弄清楚爲什麼。ScriptManager.RegisterStartupScript代碼不工作 - 爲什麼?
ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID,
"alert('This pops up')", true);
任何想法?
我以前使用過這樣的代碼,可以在我的asp.net網頁上成功彈出警告消息。現在它不工作。我無法弄清楚爲什麼。ScriptManager.RegisterStartupScript代碼不工作 - 爲什麼?
ScriptManager.RegisterStartupScript(this, typeof(Page), UniqueID,
"alert('This pops up')", true);
任何想法?
關閉我的頭頂:
GetType()
,而不是typeof(Page)
以腳本綁定到實際的頁面類,而不是基類,Page.UniqueID
關鍵不變,這是不是意義,因爲它應該由名爲控件使用,PreRender
階段註冊腳本:protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "YourUniqueScriptKey",
"alert('This pops up');", true);
}
錯過了; 。加入它,它工作。謝謝! – TheMoot 2011-02-14 16:01:26
試試這個代碼...
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "script", "alert('Hi');", true);
哪裏UpdatePanel1
是id
爲Updatepanel
頁面上
我遇到了類似的問題就來了。然而,這個問題是由於我設計頁面來引入請求的方式造成的。我將所有的.js文件作爲最後一個應用到頁面的東西,因此它們在我的文檔的末尾。 .js文件包含我所有的功能。腳本管理器似乎能夠調用這個函數,它需要已經存在的js文件以及在加載時調用的函數。希望這可以幫助其他人。
你必須把UpdatePanel的ID在第一個參數,如果導致腳本的控制是內部其他UpdatePanel的使用關鍵字「這個」,而不是更新面板這裏是代碼
ScriptManager.RegisterStartupScript(UpdatePanel3, this.GetType(), UpdatePanel3.UniqueID, "showError();", true);
我試過ScriptManager.RegisterStartupScript (this,typeof(Page),「12344」, 「alert('This pop up up')」,true);它對我來說非常合適。檢查頁面的來源,看它是否發出代碼,如果沒有問題。 – rsapru 2011-02-14 15:42:28
這是因爲使用ScriptManager註冊腳本只是註冊。你需要一些東西來解僱它,就像一個按鈕onclick事件 – Fandango68 2017-03-30 03:01:52