CALL A FUNCTION ON BUTTON ONCLICK

john rob

Total Post:108

Points:756
Posted by  john rob
C#
 1078  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. Sumit Kesarwani

    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);

    }

Answer

NEWSLETTER

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