---
title: "Call a function on Button OnClick"  
description: "Call a function on Button OnClick"  
author: "Anonymous User"  
published: 2014-08-28  
updated: 2014-08-28  
canonical: https://www.mindstick.com/forum/2184/call-a-function-on-button-onclick  
category: "c#"  
tags: ["c#", ".net", "function call on button click", "call function on server side", "open source", "button click event"]  
reading_time: 1 minute  

---

# Call a function on Button OnClick

is there a way to call a [function in asp.net](https://www.mindstick.com/forum/322/calling-javascript-function-in-asp-dot-net-mvc) using c# from [code behind](https://www.mindstick.com/forum/2199/call-javascript-s-function-from-code-behind) when a [button is clicked](https://www.mindstick.com/forum/157821/write-a-jquery-code-that-selects-all-the-checkboxes-in-a-form-when-a-select-all-button-is-clicked).

Button btnRemove = new Button();

btnremove.OnClientclick = [Remove](https://yourviews.mindstick.com/story/4554/8-harmful-weeds-to-remove-from-garden)(ID) something like that??

I want to call a function

[public void](https://www.mindstick.com/interview/2715/can-we-write-static-public-void-instead-of-public-static-void) Remove(int ID)

{

}

[Thank you in advance](https://answers.mindstick.com/qa/40482/why-was-1968-a-year-of-tension-and-turmoil-list-10-events-1-being-the-best-and-10-the-worst-thank-you-in-advance)!!

## Replies

### Reply by Sumit Kesarwani

Hi John,\

If you want call server method you can use OnClick

```
Button1.Click += new EventHandler(this.Button1_Click);void Button1_Click (object sender, EventArgs e){    var control =
(Button)sender;   
Remove(control.Id);}But you can also override your Click delegateprotected override void OnClick(EventArgs e){    Remove(this.Id);}
```


---

Original Source: https://www.mindstick.com/forum/2184/call-a-function-on-button-onclick

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
