简体   繁体   English

JavaScript确认错误值后,Response.Redirect()无法正常工作

[英]Response.Redirect() not working after javascript confirm got false value

I had a simple page like this: 我有一个简单的页面,像这样:

A.aspx - has an asp TabControl make user change to B.aspx or back, and a button will use javascript confirm user to do something. A.aspx-具有asp TabControl,可让用户更改为B.aspx或返回,然后使用Java确认用户执行操作的按钮。

B.aspx - has the same TabControl like A.aspx , just show some message here. B.aspx-具有与A.aspx相同的TabControl,仅在此处显示一些消息。

button code in A.aspx like this: A.aspx中的按钮代码如下:

<button id="do" onclick="if (confirm('you sure?')==false) { return false; };"></button>

and my Response.Redirect code in A.aspx.cs TabControl_TabChanged() like this: 以及我在A.aspx.cs TabControl_TabChanged()中的Response.Redirect代码,如下所示:

Response.Redirect("b.aspx");

It work fine before I click the button, if I click it and select 'ok' it still fine, but when I select 'cancel', the Response.Redirect() will run but the page didn't change. 在单击按钮之前,它工作正常,如果单击它并选择“确定”,它仍然可以正常工作,但是当我选择“取消”时,Response.Redirect()将运行,但页面没有更改。 please help me find the problem. 请帮助我发现问题。

只需将JavaScript的“ onclick”替换为“ OnClientClick”即可。

I would try to set a jQuery event on my Button 我会尝试在我的Button上设置一个jQuery事件

<form id="submitform">
 <button id="do" >change</button>
</form>

 $("#do").click(function(e) {
  var r=confirm("you sure?");
       if (r===false)
       {
          e.preventDefault();
       }
 });

perhaps this helps 也许这有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM