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

2020-04-01 21:51发布

问题:

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=".."> to a function in my myEditPage.aspx.cs.

How can I do so?

回答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="#" 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/



标签: c# html asp.net