0

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>
Rexxo
  • 156
  • 3
  • 16

3 Answers3

3

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>
PraveenVenu
  • 8,217
  • 4
  • 30
  • 39
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.

Stilgar
  • 22,354
  • 14
  • 64
  • 101
  • Hmm that doesn't seem to work, do I need to do something with the .ClientID? – Rexxo Mar 06 '12 at 12:38
  • Ahh, the CSS approach seemed to work. It's fine as the button is the only one to use that class. Thanks!! – Rexxo Mar 06 '12 at 12:42
0
use ()

you have to execute the func ...

 OnClientClick="overlay()"
Royi Namir
  • 144,742
  • 138
  • 468
  • 792