一佳一

记录像1+1一样简洁的代码

导航

asp.net 后台调用confirm

Posted on 2013-12-04 18:43  一佳一  阅读(419)  评论(0编辑  收藏  举报

using System;
using System.Web.UI;

public partial class _Default : System.Web.UI.Page, IPostBackEventHandler
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            ScriptManager.RegisterStartupScript(this, this.GetType(), "confirm",
                "if(confirm('你确定1+1=2吗?'))" + this.ClientScript.GetPostBackEventReference(this, "确定") + "; else " +
                this.ClientScript.GetPostBackEventReference(this, "不确定"), true);
    }

    public void RaisePostBackEvent(string eventArgument)
    {
        string res;
        switch (eventArgument)
        {
            case "确定":
                res = "太有才了!";      //处理各种后台任务
                break;
            case "不确定":
                res = "是块当实习生的料。";     //处理各种后台任务
                break;
            default:
                throw new NotSupportedException();
        }
        ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('" + res + "');", true);
    }
}