How can I programmatically call my .net button's onclick in page load?

后端 未结 5 1564
囚心锁ツ
囚心锁ツ 2021-01-16 23:06

I have a onclick event that is like:

public void OnMyButton_Click(object sender, EventArgs e)

How can I call this from within pageload?

5条回答
  •  既然无缘
    2021-01-16 23:33

    Event handlers are just normal methods - you can call them from anywhere within the class they're defined in - so Dan's answer is technically correct, although I feel he leaves out a bit of best-practice advice.

    Instead of calling your event handler from your load event, you should move the code in your event handler into another method, and then call that method from within both your click event handler, and your page load method.

提交回复
热议问题