最近也在看一些asp.net Ajax 的資料,在網(wǎng)上看到很多人都在問如何在updatepanel中注冊(cè)腳本,我也試了一下,不過(guò)總是不行,就看了好多資料,最后才知道自己沒有完全理解 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)該寫updatepanel的ID).
type (Type) :這個(gè)參數(shù)是注冊(cè)腳本塊控件的類型,即updatepanel的類型。
key (String) :這個(gè)參數(shù)是腳本酷塊的惟一標(biāo)識(shí)(關(guān)鍵字)
script (String) :這個(gè)參數(shù)是要注冊(cè)的腳本字符串.
addScriptTags (Boolean) :這個(gè)參數(shù)表示是否要在您的字符串兩邊使用“<script>”和“</script>”包圍起來(lái).
然后這是我寫的一個(gè)簡(jiǎn)單的例子:
Html代碼:
<html xmlns="<head runat="server">
<title>Untitled Page</title>
<link href="/aspnet_client/System_Web/2_0_50727/CrystalReportWebFormViewer3/CSS/default.css"
rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" >
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</ContentTemplate>
</asp:UpdatePanel>
</form>
</body>
</html>
CS代碼:
PRotected void Button1_Click(object sender, EventArgs e)
{
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, typeof(UpdatePanel), "test", "alert('test');", true);
}
以上是我的理解,如果有不正確的地方,請(qǐng)大家糾正,我先放到首頁(yè),其實(shí)沒有什么技術(shù)含量,主要是用來(lái)讓那些還不知道如何注冊(cè)的朋友看到.過(guò)后dohu可以刪了。
http://www.companysz.com/sunlife/archive/2006/11/05/550520.html
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注