OnClientClick和OnClick on asp:button [英] OnClientClick and OnClick on asp:button

查看:79
本文介绍了OnClientClick和OnClick on asp:button的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有一个同时使用OnClientClick和OnClick的按钮.

onClientClick可以很好地工作,但是当不满足onClientClick条件时,不会触发服务器端单击事件.

Hey everyone,

I have a button in which I am using both OnClientClick and OnClick.

The onClientClick works well, but when onClientClick condition is not met, Server side click event is not fired.

<asp:Button ID="btnDelete" runat="server" Text="Delete" Style="float: left; margin-right: 10px; color: black; font-weight: bold; margin-left: 40px" Height="26px" Width="67px" OnClientClick = "javascript:selectedItems(); return false;" OnClick = "btnDelete_Click" CausesValidation="false" />





function selectedItems()
         {
          var MasterTable = $find("<%=RadGrid1.ClientID%>").get_masterTableView();
          var selectedItemsCount = MasterTable.get_selectedItems().length;
          if (selectedItemsCount == 0) {
              alert("Select at least one item!");
              return false;
                       }
                     }

推荐答案

find(" ).get_masterTableView(); var selectedItemsCount = MasterTable.get_selectedItems().length; 如果(selectedItemsCount == 0 ){ alert(" ); 返回 ; } }
find("<%=RadGrid1.ClientID%>").get_masterTableView(); var selectedItemsCount = MasterTable.get_selectedItems().length; if (selectedItemsCount == 0) { alert("Select at least one item!"); return false; } }


您总是返回"false".即是问题.
将javascript函数的调用更改为
You are returning ''false'' always . ie is the issue.
Change the calling of javascript function as
OnClientClick="javascript: return selectedItems();"<br />




希望对您有帮助:)




Hope this will help you :)




您的责任就在这行中

Hi,

your problme is in this line

OnClientClick="javascript:selectedItems();return false;"


如果执行"return false",则它将永远不会提交,并且OnClick(服务器端将永远不会执行).

返回假"语句应是有条件的.

像这样更改代码:


if "return false" is execute then it would never submit and OnClick(which is sever side would never executed).

"return false" statement should be conditional.

change the code like this:

OnClientClick="javascript:selectedItems();"


并且在selectedItems()javascript函数的定义中


and in the defination of selectedItems() javascript function

if (selectedItemsCount == 0) 
{                       
    alert("Select at least one item!");
    return false;
}
else
{
    // this path ensures that when user selects at least 1 item then it 
    // proceeds to server side code OnClick to be executed.
    return true;
}



希望有帮助,

谢谢
Arindam D Tewary,



Hope that helps,

Thanks
Arindam D Tewary,


这篇关于OnClientClick和OnClick on asp:button的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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