How to call function in .cs file when we click the html button in aspx file.
3 Answers
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
}
Comments
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
}
3 Comments
sudha
<input id="Button1" type="button" value="button" runat="server" /> .cs file: public void display() { Response.Redirect("default.aspx"); } How to call the display function which is in .cs file from html button click
Manoj Attal
If you want to acheive this, you should use button server control. I dont think this is acheivable in html button.
Rob
@sudha - See mine or Darin's answer. Or, do you have a specific reason for using a HTML button - i.e. is this a "mypage.htm", rather than "mypage.aspx"?