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>
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>
You can use the LinkButton
control instead and subscribe to the Click
event.
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"/>
Code behind (VB.NET):
Sub LinkButton_Click(sender As Object, e As EventArgs)
' Your code here
End Sub
Code behind (C#):
void LinkButton_Click(Object sender, EventArgs e)
{
// your code here
}
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>
Code behind (VB.NET):
Sub HtmlAnchor_Click(sender As Object, e As EventArgs)
' your code here
End Sub
Code behind (C#):
void HtmlAnchor_Click(Object sender, EventArgs e)
{
// your code here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With