ASP.net button Jquery BlockUI

萝らか妹 提交于 2019-12-25 08:04:05

问题


I'm having trouble getting an ASP button to call a jquery script, in this case BlockUI, but I'm not sure what I'm doing wrong?

<asp:Button runat="server" ID="btnAddUser" Text="Add Currency Combination" ValidationGroup="valSum2" CssClass="showHide" OnClientClick="overlay"

    <script type="text/javascript" language="javascript">
    $(document).ready(function() { 
        $('#overlay').click(function() { 
        $.blockUI({ overlayCSS: { backgroundColor: '#00f' } }); 
    setTimeout($.unblockUI, 2000);
    }); 
});  </script>

回答1:


You can call it using the css classname .ShowHide

    <script type="text/javascript" language="javascript">
    $(document).ready(function() { 
        $('.showHide').click(function() { 
        $.blockUI({ overlayCSS: { backgroundColor: '#00f' } }); 
    setTimeout($.unblockUI, 2000);
    }); 
});  </script>



回答2:


Your script is looking for a DOM element with ID "overlay" which does not exist. The id of the button is btnAddUser.ClientID

<asp:Button runat="server" ID="btnAddUser" Text="Add Currency Combination" ValidationGroup="valSum2" CssClass="showHide" />  

    <script type="text/javascript" language="javascript">  
    $(document).ready(function() {   
        $('<%= btnAddUser.ClientID %>').click(function() {   
        $.blockUI({ overlayCSS: { backgroundColor: '#00f' } });   
    setTimeout($.unblockUI, 2000);  
    });   
});  </script>  

Note the removal of OnClientClick!

Alternatively you can make this code a named function and type its name in the OnClientClick property. You can also bind by CssClass ( $('.showHide') ) (see @PraveenVenu's answer) but this will bind the function to all elements that use this css class.




回答3:


use ()

you have to execute the func ...

 OnClientClick="overlay()"


来源:https://stackoverflow.com/questions/9583588/asp-net-button-jquery-blockui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!