【问题标题】:modalpopupextender: button clicked but postback needs to be 'stopped'modalpopupextender:单击按钮但需要“停止”回发
【发布时间】:2013-09-05 17:42:51
【问题描述】:

我有一个 ASP.NET webforms 应用程序,我只想在用户未登录时显示弹出窗口。显示弹出窗口的事件由单击按钮触发,然后后面的代码显示模式弹出窗口,如果用户未登录。

问题是页面被刷新(回发),然后才显示弹出窗口。我想要实现的是在不刷新页面的情况下弹出显示。

有什么想法吗?

谢谢,

汤姆

【问题讨论】:

    标签: asp.net webforms postback modalpopupextender


    【解决方案1】:

    '我希望在不刷新页面的情况下显示弹出窗口'

    以下是如何制作仅在用户登录时提交的提交按钮(通过添加客户端验证)。该按钮将:
    - 为未登录的用户提供弹出窗口,不做任何其他事情

    - 为已登录用户提交/回发。

      <form ...>
        ...
        <button type="submit" onclick="checkIfUserIsLoggedIn(event);">Submit</button>
        <script type="text/javascript">
        function checkIfUserIsLoggedIn(event) {
            if (userIsNotLoggedIn()) {  //userIsNotLoggedIn() is a js function you'll need to write
                alert("Please log in and re-submit.");
                event.preventDefault();  // prevent submission / postback
                event.stopPropogation(); // prevent submission / postback, probably unnecessary
            }
        }
        </script>
      </form>
    

    【讨论】:

      猜你喜欢
      • 2012-11-25
      • 2010-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-25
      • 2016-03-26
      • 2012-12-06
      • 1970-01-01
      相关资源
      最近更新 更多