Home > DeveloperSection > Forums > Call a function on Button OnClick
john rob

Total Post:108

Points:756
Posted on    August-28-2014 1:29 AM

 C#
Ratings:


 1 Reply(s)
 760  View(s)
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!!



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-28-2014 2:16 AM

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

}


Don't want to miss updates? Please click the below button!

Follow MindStick