Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to prevent page refresh using javascript??
Posted
Updated 16-Nov-20 19:52pm

To prevent the load from refreshing, you could use the JavaScript void() function and pass a parameter of 0 (zero).

if you want to know more details please follow this url:
http://www.quackit.com/javascript/tutorial/javascript_void_0.cfm
 
Share this answer
 
v2
Comments
Member 10276220 20-Dec-13 2:52am    
how to do this??
Member 10276220 20-Dec-13 2:56am    
its not working
nuke_infer 20-Dec-13 2:58am    
plz follow the url
Member 10276220 20-Dec-13 2:59am    
i did id...but its not working...how to write the code??
i wanna use it in script function
nuke_infer 20-Dec-13 3:01am    
ok you can this also

All that you have to do is just copy this piece of code in your <HEAD> tag of HTML page (or where you have your other javascript functions).
function showKeyCode(e)
{
//alert("Inside function showKeyCode(e)");
var keycode =(window.event) ? event.keyCode : e.keyCode;

if(keycode == 116)
{
event.keyCode = 0;
event.returnValue = false;
return false;
}
}

And call this function on onKeyDown event in your <BODY> tag.
I have used this code and have been successfuly to stop the page refresh.

enjoy!!!!
Suppose one Button is causing PostBack.

So, what you need to do is define...
OnClientClick = "return someJavaScriptFunction()"
in that Button's Markup.

And in that JavaScript function, just return false.
JavaScript
function someJavaScriptFunction()
{
    // Put some logic here according to your requirement.
    if(YourLogicIsSatisfied)
    {
        return false; // Then it won't PostBack.
    }

    return true; // Then It will PostBack.
}
 
Share this answer
 
Comments
Maciej Los 20-Dec-13 3:43am    
+5!
Thanks a lot Maciej Los... :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900