如何从页面加载事件中调用按钮单击事件 [英] how to call button click event from page load event

查看:121
本文介绍了如何从页面加载事件中调用按钮单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从页面加载事件中调用按钮单击事件

是否可以在页面加载事件中调用按钮单击事件????

如果可能的话,请给我一个在asp.net

how to call button click event from page load event

is it possible to call button click events in page load events ???

if is possible give me idea of apply this in asp.net

推荐答案

中应用此代码的想法:这样做不是一个好主意:相反,请从Button中提取代码将click事件转换为新方法,然后从两者中进行调用.
It''s not a good idea to do that: instead, abstract the code from the Button click event into a new method, and call that from both.


类似这样的
something like this
protected void Page_Load(object sender, EventArgs e)
{
btn_Click(btn, new EventArgs());
}
protected void btn_Click(object sender, EventArgs e)
{
}


以下是实现目标的良好实践.

The following is the good Practise to achieve your objective.

protected void Page_Load(object sender, EventArgs e)
{
functionName();
}
protected void btn_Click(object sender, EventArgs e)
{
 functionName();
}

public void functionName()
{

//function code goes here, and call this function where ever you want
}



最好的..!



All the Best..!


这篇关于如何从页面加载事件中调用按钮单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆