如何从页面加载事件中调用按钮单击事件
问题描述:
如何从页面加载事件中调用按钮单击事件
是否可以在页面加载事件中调用按钮单击事件????
如果可能的话,请给我一个在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..!