Disable page refresh after ASP.NET button is clicked

I have an asp button that looks like this:

Default.aspx

<asp:button id="button1" runat="server" Text="clickme" onclick="function" />

Default.aspx.cs

protected void function(object sender EventArgs e)
{
    // Do some calculation
}

However, whenever I click the button, the whole page is updated. I looked at this site and found many solutions, but none of them work for my project. Here are some suggested solutions:

  • set onclick = "return false;" // but then how do I run a function in code?
  • use! IsPostBack in Page_Load //, but the page is still fully updated. I do not want Page_Load to be called at all.
  • Disabling AutoEventWireup.// make it true or false does not matter.

Does anyone have a solution, or is it really impossible?

+4
3

"". script , - :

 <asp:ScriptManager runat="server" ID="sm">
 </asp:ScriptManager>
 <asp:updatepanel runat="server">
 <ContentTemplate>
 <asp:button id="button1" runat="server" Text="clickme" onclick="function" />
 </ContentTemplate>
 </asp:updatepanel>

, . , MSDN.

+8

, , ASP.Net.

, . ASP.Net , html. html- . , . : , , .Net. , .

, , , HTTP- . , HTTP- -, , , , , ASP.Net( -) .

, , , . - Page_Load if (!IsPostBack) { }. - [WebMethod] ajax . - javascript ASP.Net UpdatePanel.

, , , .

+4

asp.net, postback , .

, , - - -, jquery -. , viewstate.

, asp.net ajax: http://www.asp.net/ajax

jquery wcf: http://www.codeproject.com/Articles/132809/Calling-WCF-Services-using-jQuery

+1

All Articles