用戶端指令碼 (VB.NET)
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Button1.OnClientClick = "return function1();"
Button2.OnClientClick = "function2()"
Button3.OnClientClick = "function3()"
ClientScript.RegisterClientScriptBlock(Me.GetType(), "1", _
" function function1() { alert ('這是RegisterClientScriptBlock...'); return false;}", True)
ClientScript.RegisterStartupScript(Me.GetType(), "2", _
" function function2() { alert ('這是RegisterStartupScript...'); }", True)
ClientScript.RegisterClientScriptInclude(Me.GetType(), "3", _
"JScript.js")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" />
</div>
<asp:Button ID="Button2" runat="server" Text="Button" />
<br />
<asp:Button ID="Button3" runat="server" Text="Button" />
</form>
</body>
</html>
jscript.js
function function3() {
alert ('這是RegisterClientScriptInclude...');
}
如有錯誤 歡迎指正