事件执行到一半时,要和页面互动,除了用ajax还有什么办法。写了一个方法
#########前台的aspx#########
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 language="javascript" type="text/javascript">
function posted() {
if (confirm("后台是否继续操作?")) {
document.getElementById('HiddenField1').value = "true";
document.getElementById('Button1').click()
}
else {
document.getElementById('HiddenField1').value = "false";
document.getElementById('Button1').click()
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
<asp:HiddenField ID="HiddenField1" runat="server" Value="OK" />
</form>
</body>
</html>#########后台的 CS #########
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void Button1_Click(object sender, EventArgs e)
{
string mags = "";
//第一次执行
if (this.HiddenField1.Value == "OK")
{
this.Label1.Text = "有用的数据!";//保存后续需要的数据到缓存
//(前台)弹出对话框!
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "posted()", true);
}
//选择确定
else if (this.HiddenField1.Value == "true")
{
mags = "你选择了继续执行!" + this.Label1.Text;//需要得到第一次执行的数据
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('" + mags + "')", true);
this.HiddenField1.Value = "OK";
//清空缓存
this.Label1.Text = "执行了清空";
}
//选择取消
else if (this.HiddenField1.Value == "false")
{
mags = "你不继续执行了!";
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('" + mags + "')", true);
this.HiddenField1.Value = "OK";
//清空缓存
this.Label1.Text = "清空";
}
}
}
#########前台的aspx#########
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 language="javascript" type="text/javascript">
function posted() {
if (confirm("后台是否继续操作?")) {
document.getElementById('HiddenField1').value = "true";
document.getElementById('Button1').click()
}
else {
document.getElementById('HiddenField1').value = "false";
document.getElementById('Button1').click()
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
</div>
<asp:HiddenField ID="HiddenField1" runat="server" Value="OK" />
</form>
</body>
</html>#########后台的 CS #########
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{}
protected void Button1_Click(object sender, EventArgs e)
{
string mags = "";
//第一次执行
if (this.HiddenField1.Value == "OK")
{
this.Label1.Text = "有用的数据!";//保存后续需要的数据到缓存
//(前台)弹出对话框!
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "posted()", true);
}
//选择确定
else if (this.HiddenField1.Value == "true")
{
mags = "你选择了继续执行!" + this.Label1.Text;//需要得到第一次执行的数据
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('" + mags + "')", true);
this.HiddenField1.Value = "OK";
//清空缓存
this.Label1.Text = "执行了清空";
}
//选择取消
else if (this.HiddenField1.Value == "false")
{
mags = "你不继续执行了!";
Page.ClientScript.RegisterStartupScript(this.GetType(), "MyScript", "alert('" + mags + "')", true);
this.HiddenField1.Value = "OK";
//清空缓存
this.Label1.Text = "清空";
}
}
}
$.ajax({
url:"后台处理的页面地址",
type:"post或get,一个表单提交,一个URL里面带参数",
data:"A=xxx&B=xxxxxx表单提交传递的数据"
success:function(msg){
处理的页面输出的内容,response.write
}
})后台处理页面接到data,Form[]获取,处理之后输出 jquery的msg多调试 多断点 程序就越清晰