从后面的代码执行单击元素

时间:2015-11-13 09:08:29

标签: c# asp.net click

如何在此链接上执行c#后面的代码点击:

<a href="#close" title="Close" id="link_chiudi" class="close" runat="server"></a>

id = "link_chiudi"

1 个答案:

答案 0 :(得分:1)

添加onServerClick

<a href="#close" title="Close" id="link_chiudi" class="close" runat="server" onServerClick="link_chiudi_OnServerClick"></a>

protected void link_chiudi_OnServerClick(object sender, EventArgs e)
{

}

或者:

protected void Page_Load(object sender, EventArgs e)
{
     link_chiudi.ServerClick += link_chiudi_ServerClick;
}

void link_chiudi_ServerClick(object sender, EventArgs e)
{

}

但我建议您使用LinkButton,因为它是ASP.Net服务器端控件:

<asp:LinkButton ID="LinkButton1" runat="server" OnClick="LinkButton1_OnClick">LinkButton</asp:LinkButton>

或者:

LinkButton1.Click += LinkButton1_Click;