3 回答

TA貢獻1785條經(jīng)驗 獲得超8個贊
從我的頭頂上:
使用GetType()而不是typeof(Page)為了將腳本綁定到您的實際頁面類而不是基類,
傳遞鍵常量而Page.UniqueID不是,因為它應(yīng)該由命名控件使用,所以它沒有什么意義,
以分號結(jié)束Javascript語句,
在此PreRender階段注冊腳本:
protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this, GetType(), "YourUniqueScriptKey",
"alert('This pops up');", true);
}

TA貢獻1783條經(jīng)驗 獲得超4個贊
試試這個代碼...
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, this.GetType(), "script", "alert('Hi');", true);
哪里UpdatePanel1是id為Updatepanel您的網(wǎng)頁上

TA貢獻1825條經(jīng)驗 獲得超4個贊
如果導(dǎo)致腳本的控件位于updatepanel內(nèi)部,則必須將updatepanel id放在第一個參數(shù)中,否則使用關(guān)鍵字“ this”代替更新面板,此處為代碼
ScriptManager.RegisterStartupScript(UpdatePanel3, this.GetType(), UpdatePanel3.UniqueID, "showError();", true);
添加回答
舉報