onclick,onclientclick和onserverclick的區別
onclick,onclientclick和onserverclick的區別
下面以 HTML的按鈕( system.web.ui.htmlcontrols ) 和 ASP.NET服務端按鈕 (
system.web.ui.webcontrols ) 為例:
1. HTML控件,如IMG的輸入按鈕等 的 on
注意 runat="server"。。。
<input type="button" id="btn" name="btn" value="button" runat="server" on
此處的on
2.WEB控件,如<asp:button 按鈕等 的 on
<asp:Button ID="btn" text="button" runat="server" On
此處的on
on
btn.Attributes.Add("on
總之,客戶端點擊事件先于服務器端點擊事件執行。也就是說,先執行客戶端的Javas
到服務器端執行服務器的相關代碼。
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm2.aspx.cs"Inherits="CaiPiao.WebForm2" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javas
function fnIsSearch() {
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<input id="btnImp
</div>
</form>
</body>
</html>
后臺代碼
[co
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace CaiPiao
{
public partial class WebForm2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
this.btnImp
}
public void btnImp
{
Response.Write("測試");
}
}
}