ASP.NET,自动从页面加载中单击按钮

时间:2016-02-02 13:18:39

标签: asp.net visual-studio-2012

有没有办法让页面加载运行按钮点击事件?

2 个答案:

答案 0 :(得分:1)

是的,你可以这样做。

如果你的按钮有runat =" server"你可以从代码隐藏中访问它。 您可以在page_load事件中的按钮上插入单击操作。但最好创建一个函数,其中包含从按钮单击和page_load调用的所有操作。



<asp:Button id="btn1">Click here</asp:Button>
&#13;
&#13;
&#13;

&#13;
&#13;
void Page_Load(object source, EventArgs e)
{
     doThis();
}

void btn1_click()
{
     doThis();
}

void doThis()
{
     //click actions
}   
&#13;
&#13;
&#13;

另一种方法是通过javascript。文档准备好后找到按钮并点击按钮。

答案 1 :(得分:0)

您可以在函数中包含按钮单击事件背后的逻辑,并从页面加载中调用该函数。

相关问题