【问题标题】:how to prevent button to trigger a postback on aspx如何防止按钮触发aspx上的回发
【发布时间】:2014-02-11 06:09:51
【问题描述】:

自从我上次使用 JQUERY-UI 制作网站以来已经有一段时间了。我有一个 aspx 页面,我正在尝试在点击

时添加一个弹出模式

但是当我单击按钮时它会触发“提交”,如何防止提交?它显示弹出窗口 2 秒,然后发生“提交”。

这里是html代码

    <div id="dialog-form" title="Create new user">
      <p class="validateTips">All form fields are required.</p>

      <form>
      <fieldset>
        <label for="name">Name</label>
        <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all">
        <label for="email">Email</label>
        <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all">
        <label for="password">Password</label>
        <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all">
      </fieldset>
      </form>
    </div>


    <div id="users-contain" class="ui-widget">
      <h1>Existing Users:</h1>
      <table id="users" class="ui-widget ui-widget-content">
        <thead>
          <tr class="ui-widget-header ">
            <th>Name</th>
            <th>Email</th>
            <th>Password</th>
          </tr>
        </thead>
        <tbody>
          <tr>
            <td>John Doe</td>
            <td>john.doe@example.com</td>
            <td>johndoe1</td>
          </tr>
        </tbody>
      </table>
    </div>
    <button id="create-user">Create new user</button>

【问题讨论】:

    标签: c# jquery asp.net jquery-ui popup


    【解决方案1】:

    在按钮中添加类型属性type="button"。默认为submit

    【讨论】:

      【解决方案2】:

      最简单的方法是返回 false OnClientClick,&lt;asp:Button OnClientClick="return false;"&gt;&lt;/button&gt;

      【讨论】:

        【解决方案3】:

        在您设置弹出窗口的 Jquery 代码中 最后返回false...谢谢

        【讨论】:

          【解决方案4】:

          您可以阻止提交操作 -

          $('form').on('submit',function(e){
             e.preventDefault();
          });
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2016-10-27
            • 2022-12-03
            • 1970-01-01
            • 2015-07-08
            相关资源
            最近更新 更多