Ways of avoiding postback on calling Javascript Function

Posted by Rajesh_Kumar under JavaScript category on | Points: 40 | Views : 1608
1st way:
Write return false inside function as
<script type ="text/javascript">
function alert_message()
return false;

<asp:Button ID="btn_alert1" runat="server" Text="Get Alert" OnClientClick="alert_message();" />

2nd way:
Just write return false then semicolon after Javascript function in Button OnClientClick event as:-

No need to write return false inside function

<asp:Button ID="btn_alert2" runat="server" Text="Get Alert" OnClientClick="alert_message(); return false;" />

function alert_msg()
alert('Rajesh Kumar');

3rd way:
Using OnSubmit event of Form Tag as

<form name="form1" onsubmit = "return alert_message()">

<input type="submit" name="Submit" value="Get Alert"/>


//My Javascrip function is as:

function alert_message()
alert("Hello Rajesh");

return false;

Comments or Responses

Login to post response