Onclientclick和按钮单击事件无法收集 [英] Onclientclick and button click event not work togather

查看:60
本文介绍了Onclientclick和按钮单击事件无法收集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当弹出窗口打开时,我给出一个值并单击按钮。问题是听到当我点击按钮它将加载页面,插入的值将清除。所以,我希望当我点击按钮时它不应该加载,我必须运行我的按钮点击事件。





< asp:Button ID =btnfirstnextTabIndex =1runat =serverText =Nextclass =next1 action-buttonOnClientClick =return false; OnClick =btnfirstnext_Click/>



我尝试过:



OnClientClick =return false;当我使用它时,它不会触发按钮点击事件

和i,如果我删除OnClientClick =return false; ,页面将被加载,我不想要它。

when popup window on , i give one value and click on button. problem is hear that when i click on button it will load the page and inserted value will clear . so, i want that when i click on button it should not tack load and my button click event must me run.


<asp:Button ID="btnfirstnext" TabIndex="1" runat="server" Text="Next" class="next1 action-button" OnClientClick="return false;" OnClick="btnfirstnext_Click" />

What I have tried:

OnClientClick="return false;" when i use this it will not fire a button click event
and i if i remove OnClientClick="return false;" , page will be load and i don't want it.

推荐答案

OnClientClick Asp:Button 将 boolean 值作为 javascript 代码或函数的输入。

如果 OnClientClick 值为 true ,它将触发( PostBack )服务器事件( OnClick ),否则它将在该页面中保持相同。



OnClientClick is an attribute for Asp:Button which takes boolean value as input from a javascript code or a function.
if the OnClientClick value is true, it will fire (PostBack) the server Event (OnClick), else it will remain same in that page.

OnClientClick ="return true" // It will fire OnCick event 




OnClientClick ="return false" // It wont do any action.





现在你可以编写适合你需要的代码。


通过defalut OnClientClick 设置为 true ,如果你还没有在标签中添加属性。



如果你想从一个函数中调用它。





Now you can write your code which suits your requirement.

By defalut the OnClientClick is set to true, if you have not added the attribute in the tag.

if you want to call it from a function.

function SomeJsFunction()
      {
          // write some logic/Validation/etc in such a way that it returns boolean value ( true|false)
          if (....Your Code.....)
              return true;
          else
              return false;
      }







OnClientClick="return SomeJsFunction();"


这篇关于Onclientclick和按钮单击事件无法收集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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