Ravindra Kumar Ravindra Kumar - 1 year ago 91
ASP.NET (C#) Question

calling javascript function on OnClientClick event of a Submit button

In my asp.net page, I have three textboxes and one button.

First two textboxes are being used to get the value from the user and third one is being used to show the sum of first two boxes.

I am calling a javascript function to sum the values and show the result value on

event of that BUTTON.

JS function is working fine but when I am pressing button to get the sum, it shows the result in third textbox and just then the page is being postback and result value becomes disappear from the third textbox.

Why the postback is called by the button?

I don`t want page to be postbacked on click of submit button.

Any sugestion is appriciated.


Answer Source

OnClientClick="SomeMethod()" event of that BUTTON it by default return "true" so after that function it do postback

for solution use

//use this code in BUTTON  ==>   OnClientClick="return SomeMethod();"

//and your function like this
<script type="text/javascript">
  function SomeMethod(){
    // put your code here 
    return false;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download