var waiting_win; function OpenWaiting() {
waiting_win = window.open('../waiting.aspx', 'WaitingWin', 'left='
+ (screen.availWidth - 300) / 2 + ',top='
+ (screen.availHeight - 200) / 2 + ',width=300,height=200');
} function window_OnUnLoad() {
alert(waiting_win);
if (typeof (waiting_win) != "undefined" && waiting_win != null) {
try {
waiting_win.opener = null; waiting_win.close();
}
catch (ex) { }
}
}OpenWaiting方法是赋给了一个button.attribute.add("onclick","")这种方式。而window_OnUnLoad()方法则是在button的事件执行成功之后调用的
ClientScript.RegisterStartupScript(ClientScript.GetType(), "12", "<script>window_OnUnLoad();</script>");,可是这里无法关闭这个提示框。
alert(waiting_win);这段代码竟然提示"undefined"
waiting.aspx这个页面就是显示一个耗时提示,如下图:
waiting_win = window.open('../waiting.aspx', 'WaitingWin', 'left='
+ (screen.availWidth - 300) / 2 + ',top='
+ (screen.availHeight - 200) / 2 + ',width=300,height=200');
} function window_OnUnLoad() {
alert(waiting_win);
if (typeof (waiting_win) != "undefined" && waiting_win != null) {
try {
waiting_win.opener = null; waiting_win.close();
}
catch (ex) { }
}
}OpenWaiting方法是赋给了一个button.attribute.add("onclick","")这种方式。而window_OnUnLoad()方法则是在button的事件执行成功之后调用的
ClientScript.RegisterStartupScript(ClientScript.GetType(), "12", "<script>window_OnUnLoad();</script>");,可是这里无法关闭这个提示框。
alert(waiting_win);这段代码竟然提示"undefined"
waiting.aspx这个页面就是显示一个耗时提示,如下图:
ClientScript.RegisterStartupScript(ClientScript.GetType(), "12", "<script>window_OnUnLoad();</script>");,
看看你页面源码 看看是否注册成功??????
还有你好像逻辑有点问题: OpenWaiting方法是赋给了一个button.attribute.add("onclick","")这种方式。而window_OnUnLoad()方法则是在button的事件执行成功之后调用的;OpenWaiting也应该在后台注册才有效果 不然运行服务器端代码 那你js变量值肯定不会存在了啊
ClientScript.RegisterStartupScript(ClientScript.GetType(), "12", "<script>window_OnUnLoad();</script>");,
var waiting_win;
同样提示undefined
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMjA0OTM4MTAwNA9kFgICAw9kFgICAQ8PZBYCHgdvbmNsaWNrBQ1PcGVuV2FpdGluZygpZGQzVD93klhGC7dtK58mhv0l2gLb3Q==" />
</div><div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKKhpGADQLcu4S2BAkMuQLquYRQ80GZ20fY4Fxk8Pxm" />
</div>
<div>
<input type="submit" name="submit" value="执行" onclick="OpenWaiting();" id="submit" />
</div>
<script >window_OnUnLoad();</script></form>
waiting_win = window.open('../waiting.aspx', 'WaitingWin', 'left='
+ (screen.availWidth - 300) / 2 + ',top='
+ (screen.availHeight - 200) / 2 + ',width=300,height=200');
return false;
}设置submit按钮不提交(回发) UseSubmitBehavior="false"
<head>
var waiting_win;
</head>
这样可以??
设置submit按钮不提交(回发) UseSubmitBehavior="false"
可是我真正的应用程序是点击按钮是需要做操作很多事情的
两个方法同时都用client.register方法注册就行
可是我这样控制不了这个弹出窗口的打开与关闭的时间啊像我现在是需要点击按钮把弹出框打开,然后按钮的事情里操作完成之后再关闭。
{
ClientScript.RegisterStartupScript(ClientScript.GetType(), "12555", "<script >OpenWating();</script>");
} protected void submit_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(10000);
ClientScript.RegisterClientScriptBlock(ClientScript.GetType(), "12", "<script >window_OnUnLoad();</script>"); }
<%= js%>
</head>js="<script >window_OnUnLoad();</script>";
我要是同时把打开新窗口和关闭新窗口的代码全放到点击按钮事件里去执行的话,那这两段代码都是同时执行了。
ClientScript.RegisterStartupScript(ClientScript.GetType(), "12555", "<script >OpenWating();
ClientScript.RegisterClientScriptBlock(ClientScript.GetType(), "12", "<script >window_OnUnLoad();
也就是说根本无法打开新窗口。
所以我就是想在 button.attribute.add(onclick)放openWaiting方法而在按钮事件里放window_OnUnload()方法关闭窗口我想实现的功能就是当点击按钮的时候弹出提示正在执行。当执行完毕之后有返回值或者报错就把弹出窗口给关闭
protected void Page_Load(object sender, EventArgs e)
{
submit.Attributes.Add("onclick", "OpenWaiting()");
} protected void submit_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(10000); closeJs = "<script>window_OnUnLoad();</script>";
}
<head runat="server">
<title></title> <script language="javascript" type="text/javascript">
var waiting_win;
function OpenWaiting() {
waiting_win = window.open('../waiting.aspx', 'WaitingWin', 'left='
+ (screen.availWidth - 300) / 2 + ',top='
+ (screen.availHeight - 200) / 2 + ',width=300,height=200');
} function window_OnUnLoad() {
alert(waiting_win);
if (typeof (waiting_win) != "undefined" && waiting_win != null) {
try {
waiting_win.opener = null; waiting_win.close();
}
catch (ex) { }
}
}
</script> <%=closeJs %>
</head>
protected string closeJs;
protected string openJs;
protected void Page_Load(object sender, EventArgs e)
{
} protected void submit_Click(object sender, EventArgs e)
{
openJs = "<script>OpenWaiting();</script>";
System.Threading.Thread.Sleep(10000); closeJs = "<script>window_OnUnLoad();</script>";
}后台代码要是改成这样是可以的。
可是根本不会弹出框来,而是过了十秒之后再弹出然后立刻关闭。
与我想要的效果不一样呀
我对ajax不懂,所以没用。
protected string openJs;
protected void Page_Load(object sender, EventArgs e)
{
} protected void submit_Click(object sender, EventArgs e)
{
openJs = "<script>OpenWaiting();</script>";
System.Threading.Thread.Sleep(10000); closeJs = "<script>window_OnUnLoad();</script>";
}这种方法就对了
可是它弹出框不是执行到 openJs = "<script>OpenWaiting();</script>";这里弹出来。
而是需要整个button事件完毕 了和再弹出来,也就是说弹出和关闭同时进行了
杯具。。
只不过因为我还有另外一个unbeforeunload事件已经放在body里了
所以我需要在后台执行window_UnLoad方法。
难道就没有好的方法了吗
protected void submit_Click(object sender, EventArgs e)
{
openJs = "<script>OpenWaiting();</script>";
System.Threading.Thread.Sleep(10000); closeJs = "<script>window_OnUnLoad();</script>";
}
这种方法根本就没有作用,,逻辑有问题,,服务器执行完了,,才把JS 发回客户端的,所以 相当于 用户要毫无意义的等进度条滚动,,事实上操作执行完了可以说这种方法是错的
在我现有的这些代码上。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> <script type="text/javascript">
var waiting_win;
function OpenWaiting() {
waiting_win = window.open('Canledar.aspx', 'WaitingWin', 'left=' + (screen.availWidth - 300) / 2 + ',top=' + (screen.availHeight - 200) / 2 + ',width=300,height=200');
} function window_OnUnLoad() {
if (typeof (waiting_win) != "undefined" && waiting_win != null) {
try { waiting_win.opener = null; waiting_win.close(); } catch (ex) { }
}
}
function Excute() {
OpenWaiting();
PageMethods.ExecuteFun(CloseMsg);
} function CloseMsg(res) {
if (res == "true") {
window_OnUnLoad();
}
}
</script></head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
</asp:ScriptManager>
<input type="button" value="执行" onclick="Excute();" />
</form>
</body>
</html> [WebMethod]
public static string ExecuteFun()
{
System.Threading.Thread.Sleep(10000);
return "true";
}
简单的一个小例子,,看是不是你想要的
我想要做的基本上都在这里面。
http://topic.csdn.net/u/20100629/15/6f50440d-a291-4f5f-a57e-bb2f637c2905.html
现在应该会看得懂
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title> <script>
var waiting_win; function OpenWin() {
waiting_win = window.open('waiting.aspx', 'WaitingWin', 'left='
+ (screen.availWidth - 300) / 2 + ',top='
+ (screen.availHeight - 200) / 2 + ',width=300,height=200');
}
function CloseWin() {
if (typeof (waiting_win) != "undefined" && waiting_win != null) {
try { waiting_win = window.open('waiting.aspx', 'WaitingWin', 'left='
+ (screen.availWidth - 300) / 2 + ',top='
+ (screen.availHeight - 200) / 2 + ',width=0,height=0'); waiting_win.opener = null; waiting_win.close();
}
catch (ex) { }
} }
</script></head>
<body>
<form id="form1" runat="server">
<asp:Button ID="btn" runat="server" OnClientClick="OpenWin();" OnClick="btn_Click"
Text="Submit" />
</form>
</body>
</html> protected void btn_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(5000);
ClientScript.RegisterStartupScript(GetType(), "CloseWin", "waiting_win='WaitingWin'; CloseWin();", true);
}
只能通过attribute.add方式添加
比如this.btn.attribute.add("onclientclick")这种方式也可以的吧?
弹不出框来,用这样写的话,你那种方法可以
---------------------------
this.submit.Attributes.Add("onclientclick", "OpenWaiting()");=》this.submit.Attributes.Add("onclick", "OpenWaiting()");