sudha
sudha

Reputation: 21

Call function when we click the html button

How to call function in .cs file when we click the html button in aspx file.

Upvotes: 1

Views: 3577

Answers (3)

Fenton
Fenton

Reputation: 250922

Make the button an and add a click event. This will post-back the page when you click it and call the function defined in the click event.

Upvotes: 0

Rob
Rob

Reputation: 45771

If you mean a traditional "Postback" style ASP.net WinForms page, then create a method in your .aspx.cs file and attach it to the button, for example:

In .aspx file:

<asp:Button runat="server" ID="myButton" OnClick="myButton_OnClick" Text="myButton" />

In .aspx.cs file:

protected void myButton_OnClick(object sender, EventArgs e)
{
 // Code to act on button click goes here
}

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1038800

When you click on a button the OnClick handler function will be called:

<asp:Button ID="btnTest" runat="server" OnClick="BtnTestClick" Text="foo" />

When you click on the button the BtnTestClick function will be called:

protected void BtnTestClick(object sender, EventArgs e)
{
    // do something
}

Upvotes: 2

Related Questions