<i id='DGDwl'><tr id='DGDwl'><dt id='DGDwl'><q id='DGDwl'><span id='DGDwl'><b id='DGDwl'><form id='DGDwl'><ins id='DGDwl'></ins><ul id='DGDwl'></ul><sub id='DGDwl'></sub></form><legend id='DGDwl'></legend><bdo id='DGDwl'><pre id='DGDwl'><center id='DGDwl'></center></pre></bdo></b><th id='DGDwl'></th></span></q></dt></tr></i><div id='DGDwl'><tfoot id='DGDwl'></tfoot><dl id='DGDwl'><fieldset id='DGDwl'></fieldset></dl></div>

        <bdo id='DGDwl'></bdo><ul id='DGDwl'></ul>
    1. <tfoot id='DGDwl'></tfoot>

        <legend id='DGDwl'><style id='DGDwl'><dir id='DGDwl'><q id='DGDwl'></q></dir></style></legend>

        <small id='DGDwl'></small><noframes id='DGDwl'>

        ASP.NET:如果使用 onclick,则不会调用 OnServerClick 事

        时间:2023-06-05
          <tbody id='NRG9L'></tbody>
          <bdo id='NRG9L'></bdo><ul id='NRG9L'></ul>
          • <legend id='NRG9L'><style id='NRG9L'><dir id='NRG9L'><q id='NRG9L'></q></dir></style></legend>

            <small id='NRG9L'></small><noframes id='NRG9L'>

            <i id='NRG9L'><tr id='NRG9L'><dt id='NRG9L'><q id='NRG9L'><span id='NRG9L'><b id='NRG9L'><form id='NRG9L'><ins id='NRG9L'></ins><ul id='NRG9L'></ul><sub id='NRG9L'></sub></form><legend id='NRG9L'></legend><bdo id='NRG9L'><pre id='NRG9L'><center id='NRG9L'></center></pre></bdo></b><th id='NRG9L'></th></span></q></dt></tr></i><div id='NRG9L'><tfoot id='NRG9L'></tfoot><dl id='NRG9L'><fieldset id='NRG9L'></fieldset></dl></div>

                • <tfoot id='NRG9L'></tfoot>
                • 本文介绍了ASP.NET:如果使用 onclick,则不会调用 OnServerClick 事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在这里遇到了一个特殊的问题,我一生都无法弄清楚解决方案是什么.请注意,以下代码不是动态创建的,而是立即在我的 aspx 文件中创建的.

                  I have a peculiar problem here and I can't by my life figure out what the solution is. Note that the following code is not dynamically created, but just immediately in my aspx file.

                  <button type="button" runat="server" id="btnSubmit"
                    OnServerClick="btnSubmit_Click" onclick="return confirm('Sure?');">
                      Submit
                  </button>
                  

                  只要我没有那里有 onclick 属性,它就可以正常工作,即 OnServerClick 处理程序按应有的方式被触发.但是当我使用 onclick 属性时,无论我是确认还是拒绝确认对话框,它都不是.

                  This works just fine as long as I don't have the onclick attribute there, i.e. the OnServerClick handler is fired as it should. But when I use the onclick attribute it is not, no matter whether I confirm or decline the confirmation dialog box.

                  我做错了什么?谢谢

                  推荐答案

                  如果您查看生成的源代码,您将看到以下内容:

                  If you look at the source code generated you will see the following:

                  onclick="return confirm('Sure?'); __doPostBack('btnSubmit','')"
                  

                  所以发生的事情是永远不会调用 _doPostBack.做你正在寻找的东西的hacky方法如下:

                  so what is happening is the _doPostBack is never called. The hacky way to do what you're looking for is the following:

                  <button type="button" runat="server" id="btnSubmit"
                    OnServerClick="btnSubmit_Click" onclick="if (confirm('Sure?')) ">
                  

                  真正正确的方法是使用 Web 控件:

                  The real correct way would be to use a Web Control:

                  <asp:Button runat="server"
                          OnClick="btnSubmit_Click" OnClientClick="return confirm('Sure?')" Text="Submit" />
                  

                  这篇关于ASP.NET:如果使用 onclick,则不会调用 OnServerClick 事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:ASP.NET/HTML:ASP.NET (.cs) 中 HTML 按钮的 onClick 属性 下一篇:OnClick 与 OnClientClick 的 asp:CheckBox?

                  相关文章

                  最新文章

                  <i id='CY6Zo'><tr id='CY6Zo'><dt id='CY6Zo'><q id='CY6Zo'><span id='CY6Zo'><b id='CY6Zo'><form id='CY6Zo'><ins id='CY6Zo'></ins><ul id='CY6Zo'></ul><sub id='CY6Zo'></sub></form><legend id='CY6Zo'></legend><bdo id='CY6Zo'><pre id='CY6Zo'><center id='CY6Zo'></center></pre></bdo></b><th id='CY6Zo'></th></span></q></dt></tr></i><div id='CY6Zo'><tfoot id='CY6Zo'></tfoot><dl id='CY6Zo'><fieldset id='CY6Zo'></fieldset></dl></div>
                    <bdo id='CY6Zo'></bdo><ul id='CY6Zo'></ul>

                  1. <legend id='CY6Zo'><style id='CY6Zo'><dir id='CY6Zo'><q id='CY6Zo'></q></dir></style></legend>

                    1. <tfoot id='CY6Zo'></tfoot>
                    2. <small id='CY6Zo'></small><noframes id='CY6Zo'>