Call a C# function in ASP.NET when clicking on a HTML link

I have some inputs and some TextAreas in my myEditPage.aspx page and I wish to upload them to a database but to do so I need to link a <a href=".." rel="nofollow noreferrer noopener"> to a function in my myEditPage.aspx.cs.

How can I do so?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Instead of

<a href=.....>

use

<asp:LinkButton id="myid" runat="server" OnClick="MyFunction_Click" />

LinkButton is an ASP.Net server side control

Of course, you can attach a function to an <a> tag as well. Just make it a server control by adding runat=server to it.

<a href="#" rel="nofollow noreferrer noopener" runat="server" onServerClick="MyFuncion_Click" />

Then in your function retrieve the values of your textareas and inputs.

In general, use asp.net controls instead of regular html controls. It makes it easier to program asp.net.

For textarea/input use <asp:TextBox>. If you google a bit you will find many tutorials to get you started with asp.net programming. For example: http://www.asp.net/


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x