最近也在看一些asp.net Ajax 的資料,在網上看到很多人都在問如何在updatepanel中注冊腳本,我也試了一下,不過總是不行,就看了好多資料,最后才知道自己沒有完全理解 ScriptManager.RegisterClientScriptBlock(Control control,Type type,string key, string script,bool addScriptTags),其中的各個參數。(注:RegisterClientScriptBlock是 ScriptManager的一個靜態方法)
參數詳解:
control (Control) :這個參數是注冊腳本塊的控件.如果你是在updatepanel中注冊時,即updatepanel (應該寫updatepanel的ID).
type (Type) :這個參數是注冊腳本塊控件的類型,即updatepanel的類型。
key (String) :這個參數是腳本酷塊的惟一標識(關鍵字)
script (String) :這個參數是要注冊的腳本字符串.
addScriptTags (Boolean) :這個參數表示是否要在您的字符串兩邊使用“<script>”和“</script>”包圍起來.
然后這是我寫的一個簡單的例子:
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);
}
以上是我的理解,如果有不正確的地方,請大家糾正,我先放到首頁,其實沒有什么技術含量,主要是用來讓那些還不知道如何注冊的朋友看到.過后dohu可以刪了。
http://www.49028c.com/sunlife/archive/2006/11/05/550520.html
新聞熱點
疑難解答