1

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

3 Answers 3

2

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
}
Sign up to request clarification or add additional context in comments.

Comments

2

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

<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
If you want to acheive this, you should use button server control. I dont think this is acheivable in html button.
@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"?
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.