从 <a href 运行代码隐藏例程 [英] Running a code behind routine from an <a href

查看:19
本文介绍了从 <a href 运行代码隐藏例程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这个 html 中的按钮的链接

I have a link that looks like a button from this html

<p class="link-styleContact"><a href="#"><span>Email Contact Form</span></a></p>

我可以通过将例程名称添加到 href 来在单击该文件时运行代码隐藏文件吗?如下图

can I run a code behind file when this is clicked on by adding the routine name to the href? like below

<p class="link-styleContact"><a href="ContactFormClicked" 
    runat="server"><span>Email Contact Form</span></a></p>

推荐答案

您可以使用 LinkBut​​ton 控件并订阅 Click 事件.

它将在浏览器上显示为一个链接,您可以在事件处理程序中使用您的代码.

It will appear as a link on the browser and you can have your code in the event handler.

aspx:

<asp:LinkButton id="myLink" Text="Hi" OnClick="LinkButton_Click" runat="server"/>

背后的代码(VB.NET):

Code behind (VB.NET):

Sub LinkButton_Click(sender As Object, e As EventArgs) 
   ' Your code here
End Sub

背后的代码(C#):

void LinkButton_Click(Object sender, EventArgs e) 
{
   // your code here
}

<小时>

或者,您可以使用 HtmlAnchor 控制并设置 ServerClick 事件处理程序.这基本上是带有 runat="server" 属性的 a 元素:


Alternatively, you can use the HtmlAnchor control and set the ServerClick event handler. This is basically the a element with a runat="server" attribute:

aspx:

<a id="AnchorButton" onserverclick="HtmlAnchor_Click" runat="server">
     Click Here
</a>

背后的代码(VB.NET):

Code behind (VB.NET):

Sub HtmlAnchor_Click(sender As Object, e As EventArgs)
   ' your code here
End Sub

背后的代码(C#):

  void HtmlAnchor_Click(Object sender, EventArgs e)
  {
     // your code here
  }

这篇关于从 &lt;a href 运行代码隐藏例程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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