<tfoot id='OQl4o'></tfoot>
      • <bdo id='OQl4o'></bdo><ul id='OQl4o'></ul>

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

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

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

      C#:调用按钮事件处理程序方法而不实际单击按钮

      时间:2023-09-16
            <tbody id='I129p'></tbody>
            <bdo id='I129p'></bdo><ul id='I129p'></ul>
              <tfoot id='I129p'></tfoot>
              <i id='I129p'><tr id='I129p'><dt id='I129p'><q id='I129p'><span id='I129p'><b id='I129p'><form id='I129p'><ins id='I129p'></ins><ul id='I129p'></ul><sub id='I129p'></sub></form><legend id='I129p'></legend><bdo id='I129p'><pre id='I129p'><center id='I129p'></center></pre></bdo></b><th id='I129p'></th></span></q></dt></tr></i><div id='I129p'><tfoot id='I129p'></tfoot><dl id='I129p'><fieldset id='I129p'></fieldset></dl></div>

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

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

              2. 本文介绍了C#:调用按钮事件处理程序方法而不实际单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我的 aspx 文件中有一个名为 btnTest 的按钮..cs 文件有一个在单击按钮时调用的函数.

                I have a button in my aspx file called btnTest. The .cs file has a function which is called when the button is clicked.

                btnTest_Click(object sender, EventArgs e)
                

                如何在我的代码中调用此函数(即不实际单击按钮)?

                How can I call this function from within my code (i.e. without actually clicking the button)?

                推荐答案

                btnTest_Click(null, null);
                

                前提是该方法没有使用这些参数中的任何一个(通常不使用.)

                Provided that the method isn't using either of these parameters (it's very common not to.)

                说实话,虽然这很恶心.如果您有需要调用的代码,则应遵循以下约定:

                To be honest though this is icky. If you have code that needs to be called you should follow the following convention:

                protected void btnTest_Click(object sender, EventArgs e)
                {
                   SomeSub();
                }
                
                protected void SomeOtherFunctionThatNeedsToCallTheCode()
                {
                   SomeSub();
                }
                
                protected void SomeSub()
                {
                   // ...
                }
                

                这篇关于C#:调用按钮事件处理程序方法而不实际单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:C# 事件处理(与 Java 相比) 下一篇:避免 C# 中的重复事件订阅

                相关文章

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

                1. <small id='Hi6YK'></small><noframes id='Hi6YK'>