confirm 确认框的一个实际应用(续)时间:2022-08-30 14:26:34在 confirm 确认框的一个实际应用 中,我使用ICallbackEventHandler接口改写了之前的方案。 现使用form post 的方式来进行改写。 <!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/javascript"> function CustomSubmit() { var form = document.getElementById('<%=form1.ClientID %>'); document.getElementById('hID').value = confirm('确认执行么?'); form.submit(); } </script> </head> <body> <form id="form1" runat="server"> <input type="hidden" id="hID" name="hName" /> <asp:Button ID="btnCallBack" runat="server" Text="回发并弹出confirm" OnClick="btnCallBack_Click" /> <br /> <asp:Literal ID="lit" runat="server"></asp:Literal> </form> </body> </html> private Dictionary<bool, Action> dic; protected void Page_Load(object sender, EventArgs e) { string value = Request.Form["hName"] ?? ""; bool result; if (bool.TryParse(value, out result)) { dic = new Dictionary<bool, Action>(); dic.Add(true, Confirm); dic.Add(false, Cancel); dic[result](); } } protected void btnCallBack_Click(object sender, EventArgs e) { // 先执行一段代码 lit.Text = DateTime.Now.ToString("yyyy-MM-dd"); //弹出confirm ClientScript.RegisterStartupScript(GetType(), "confirm", "CustomSubmit();", true); } //确认时执行的代码 private void Confirm() { lit.Text = "确认"; } //取消时执行的代码 private void Cancel() { lit.Text = "取消"; }