aparna rai
aparna rai

Reputation: 833

Avoid page refresh click on Button Asp.net c#

enter code here NET application, I have inserted a button that call a Javascript function (OnClick event) and a asp.net function (OnClick event) The problem is that when I click the button, it refreshes the page. How can I avoid the page refreshes click on asp button using javascript?

 document.getElementById('pageurl').innerHTML = "tryfblike.aspx";
          $('#<%= btnsave.ClientID %>').click();
          $('#auth-loggedout').hide();

<asp:Button runat="server"  ID="btnsave" OnClick="btnsave_Click();"  Visible="true" style="display: none;"  />

protected void btnsave_Click(object sender, EventArgs e)
{
    objda.agentid = "2";
    string currenttime = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
    objda.datetime = currenttime;
    ds = objda.tbl_log();
}

Upvotes: 0

Views: 10583

Answers (3)

Sriniwas Khatal
Sriniwas Khatal

Reputation: 1

FirstYou can call javascrip onclick and then simply add return false;

Upvotes: 0

ebram khalil
ebram khalil

Reputation: 8321

First to call JavaScript function, use OnClientClick. To avoid page refresh, after your function call add return false;

For example:

<asp:Button ID="btnSubmit" runat="Server" OnClientClick="btnsave_Click(); return false;" />

Upvotes: 2

ihsan
ihsan

Reputation: 87

in java script you can use return false. if you want prevent whole page referesh use ajax.

Upvotes: 0

Related Questions