在Submit按钮的OnClientClick事件上调用javascript函数 [英] calling javascript function on OnClientClick event of a Submit button

查看:50
本文介绍了在Submit按钮的OnClientClick事件上调用javascript函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的asp.net页面中,我有三个文本框和一个按钮.
前两个文本框用于从用户获取值,第三个文本框用于显示前两个框的总和.

In my asp.net page, I have three text boxes and one button.
First two text boxes are being used to get the value from the user and third one is being used to show the sum of first two boxes.

我正在调用一个javascript函数对这些值求和,并在该按钮的 OnClientClick 事件上显示结果值.

I am calling a javascript function to sum the values and show the result value on OnClientClick event of that BUTTON.

JS函数运行良好,但是当我按按钮求和时,它在第三个文本框中显示结果,然后页面被回发,结果值从第三个文本框中消失.

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

为什么通过按钮调用回发?
我不希望在单击提交"按钮后对页面进行后退.

Why the post-back is called by the button?
I don't want page to be post-backed on click of submit button.

任何建议都值得赞赏.

推荐答案

OnClientClick ="SomeMethod()" 事件,默认情况下返回" true "所以在执行该功能之后,它会回发

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

用于解决方案

//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;
  }
</script>

这篇关于在Submit按钮的OnClientClick事件上调用javascript函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆