protected void Page_Load(object sender, EventArgs e)
{
// 客戶端代碼
Button1.Attributes["onclick"] = "javascript:return confirm('Are you sure?')";
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Write("You push the button!");
}
如果紅色部分代碼,則程序執行結果爲:單擊按鈕後,選擇確定按鈕,則出現文字,否則不出現文字.但去掉經色部分代碼後無論選擇確定還是取消按鈕,都會出現文字.