ASPNET:Server Control與Client Script

    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!");
    } 

如果紅色部分代碼,則程序執行結果爲:單擊按鈕後,選擇確定按鈕,則出現文字,否則不出現文字.但去掉經色部分代碼後無論選擇確定還是取消按鈕,都會出現文字.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章