Call a function on Button OnClick

Total Post:108

Points:756
C#
 1313  View(s)
Ratings:
Rate this:

is there a way to call a function in asp.net using c# from code behind when a button is clicked.

Button btnRemove = new Button();

btnremove.OnClientclick = Remove(ID) something like that??

I want to call a function

public void Remove(int ID)

{

}

Thank you in advance!!

  1. Post:378

    Points:2694
    Re: Call a function on Button OnClick

    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 delegate
    protected override void OnClick(EventArgs e)
    {
        Remove(this.Id);
    }

      Modified On Apr-05-2018 04:37:00 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!