Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call C# code-behind method with a <li> onclick

I got a li - list, one with an onclick:

<ul class="tabs"> 
    <li><a href="#tab1">Foobar_1</a></li> 
    <li onclick="doMethod"><a href="#tab2">Foobar_2</a></li> 
    <li><a href="#tab3">Foobar_3</a></li> 
    <li><a href="#tab4">Foobar_4</a></li>
</ul>

Now, the method I want to call when clicked on a tab (the li's), updates an UpdatePanel, so a gridview is shown.

I know it must have something to do with AJAX, but I ain't got a clue how to move on now...

so basically: how to call a c# method using AJAX?

like image 609
Joris Avatar asked Jun 01 '10 18:06

Joris


People also ask

What is call in C?

The call by reference method of passing arguments to a function copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. It means the changes made to the parameter affect the passed argument.

Is call by value in C?

The call by value method of passing arguments to a function copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument. By default, C programming uses call by value to pass arguments.

How do you call C in C++?

Just declare the C++ function extern "C" (in your C++ code) and call it (from your C or C++ code). For example: // C++ code: extern "C" void f(int);

Does Python call C?

The python default implementation is written in C programming and it's called CPython. So it's not very uncommon to use C functions in a python program. In this tutorial, we learned how to easily call C functions in a python program.


1 Answers

<li runat="server" OnClick="DoMyOnClickCall">....</li>

Then

public void DoMyOnClickCall(object sender, EventArgs e)
{
   // sender is the li dom element you'll need to cast it though.
}

To expand: (Update)

sender is an object that represents the <li>...</li> in HTML. It's called something like HtmlControl.

You'll need to cast sender to that type.

var myLI = (HtmlControl)sender;
// do stuff with `myLI`
like image 141
Aren Avatar answered Sep 28 '22 09:09

Aren