0

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();
}
1
  • please add some code. So we can help you. Commented Jan 3, 2017 at 9:49

3 Answers 3

2

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

4 Comments

bt, how to execute btnsave_Click event
@aparnarai, remove return false; .. The return false is to stop hitting the server back
after remove return false, again reload the whole page, how to stop page refresh
if you want to execute server-side code then you either, 1- post back to the server; hence refresh the page, or 2- make an AJAX call
0

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

3 Comments

How to execute btnsave_Click event
if you want to prevent post back on button click use client side button!
for use server data you can use ajax call from client side button.
0

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

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.