最近也在看一些asp.net ajax 的資料,在網(wǎng)上看到非常多人都在問(wèn)怎么在updatepanel中注冊(cè)腳本,我也試了一下,不過(guò)總是不行,就看了好多資料,最后才知道自己沒(méi)有完全理解 ScriptManager.RegisterClientScriptBlock(Control control,Type type,string key, string script,bool addScriptTags),其中的各個(gè)參數(shù)。(注:RegisterClientScriptBlock是 ScriptManager的一個(gè)靜態(tài)方法)
參數(shù)詳解:
control (Control) :這個(gè)參數(shù)是注冊(cè)腳本塊的控件.如果你是在updatepanel中注冊(cè)時(shí),即updatepanel (應(yīng)該寫(xiě)updatepanel的ID).
type (Type) :這個(gè)參數(shù)是注冊(cè)腳本塊控件的類(lèi)型,即updatepanel的類(lèi)型。
key (String) :這個(gè)參數(shù)是腳本酷塊的惟一標(biāo)識(shí)(關(guān)鍵字)
script (String) :這個(gè)參數(shù)是要注冊(cè)的腳本字符串.
addScriptTags (Boolean) :這個(gè)參數(shù)表示是否要在你的字符串兩邊使用“”包圍起來(lái).
然后這是我寫(xiě)的一個(gè)簡(jiǎn)單的例子:
Html代碼:
CS代碼:
protected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, typeof(UpdatePanel), "test", "alert(test);", true);
}
以上是我的理解,如果有不正確的地方,請(qǐng)大家糾正,我先放到首頁(yè),其實(shí)沒(méi)有什么技術(shù)含量,主要是用來(lái)讓那些還不知道怎么注冊(cè)的朋友看到.過(guò)后dohu能刪了。
http://www.cnblogs.com/sunlife/archive/2006/11/05/550520.html
新聞熱點(diǎn)
疑難解答
圖片精選