程序执行一半后可以跳出对话框选择是否继续执行

原文发布时间为:2008-10-31 —— 来源于本人的百度文章 [由搬家工具导入]

我想这样,点击一个按钮,然后程序执行一半的时候,跳出一个选择“是否继续执行?”,这样的效果,如果我点击 是,它就继续执行,如果点击 否 ,结束。。。
基本思想:用一个按钮(按钮的width属性设成0,这样就成为了一个隐形按钮),然后判断confirm的值来确定是否用getElementById的方法点击那个“隐形按钮”。。。

主要语句:

ClientScript.RegisterStartupScript(Page.GetType(), "", " <SCRIPT>if(confirm('要输出world么?')) document.getElementById('Unnamed1').click(); </SCRIPT>");

前台 code
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %><!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 id="Head1" runat="server"> <title>Untitled Page </title> </head> <body> <form id="form1" runat="server"> <asp:button runat="server" text="隐藏按钮" onclick="Unnamed1_Click" ID="Unnamed1" Width="0px" />&nbsp; <asp:Button ID="Button1" runat="server" Text="尝试" onclick="Button1_Click" /> </form> </body> </html>



后台 code
using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;public partial class Default4 : System.Web.UI.Page{ string str = "hello"; protected void Page_Load(object sender, EventArgs e) { } protected void Unnamed1_Click(object sender, EventArgs e) { Response.Write(str+" world!"); } protected void Button1_Click(object sender, EventArgs e) { Response.Write(str); ClientScript.RegisterStartupScript(Page.GetType(), "", " <SCRIPT>if(confirm('要输出world么?')) document.getElementById('Unnamed1').click(); </SCRIPT>"); //应该写成以上这句,写下面这句将找不到button1 //Response.Write(" <SCRIPT>if(confirm('要输出world么?')) document.getElementById('Unnamed1').click(); </SCRIPT>"); } }


原文地址:https://www.cnblogs.com/handboy/p/7143851.html