Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

c#

asp.net

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?

like image 351
Alex Avatar asked Dec 27 '10 08:12

Alex


People also ask

What is function call in C?

A function-call expression has the value and type of the function's return value. A function cannot return an object of array type. If the function's return type is void (that is, the function has been declared never to return a value), the function-call expression also has void type.

Can I call ac function from Python?

We can call a C function from Python program using the ctypes module.

How do you call a function?

You call the function by typing its name and putting a value in parentheses. This value is sent to the function's parameter. e.g. We call the function firstFunction(“string as it's shown.”);


1 Answers

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/

like image 98
Mikael Svenson Avatar answered Oct 23 '22 03:10

Mikael Svenson