[英]ScriptManager.RegisterStartupScript code not working - why?
我過去曾使用這樣的代碼在我的asp.net網頁上成功彈出警報消息。 現在它不起作用。 我無法弄清楚為什么。
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);
}
試試這個代碼......
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "script", "alert('Hi');", true);
UpdatePanel1
是您網頁上Updatepanel
的id
如果導致腳本的控件位於updatepanel內,則必須將updatepanel id放在第一個參數中,否則使用關鍵字“this”代替更新面板這里是代碼
ScriptManager.RegisterStartupScript(UpdatePanel3, this.GetType(), UpdatePanel3.UniqueID, "showError();", true);
我遇到了類似的問題。 然而,這個問題是由於我設計頁面以引入請求的方式引起的。我將所有的.js文件放在最后應用於頁面的內容中,因此它們位於我的文檔的末尾。 .js文件包含我的所有功能。 腳本管理器似乎能夠調用此函數它需要js文件已經存在與加載時調用的函數。 希望這有助於其他任何人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.