简体   繁体   中英

Asp.Net Button postback keeps firing

For some reason the postback event keeps firing for my button. If I place a break point on the function(e) part with Firebug, the code just skips right over the function. Return false does not work either.

<script>
$(document).ready
(
$('#<%:FilterButton.ClientID %>').click 
  (
    function (e)
    {
      e.preventDefault();
      $('#Filter').toggle();
    }
   )
 );
</script> 

Edit: Kundan and others have pointed out that I skipped passing in an anonymous function for the document.ready() event. Careless on my part.

Try this

<script>
$(document).ready(function() {
 $('#<%= FilterButton.ClientID %>').click(function (e){
      e.preventDefault();
      $('#Filter').toggle();
      return false;
 });
});
</script>

I think you have a few issues with your code, unless it was just a bad copy/paste job. Should be:

$(document).ready(function(){

    $('#<%=FilterButton.ClientID %>').click(function(e){
        e.preventDefault();
        $('#Filter').toggle();
    });

});

Change

$('#<%:FilterButton.ClientID %>').click 

to

$('#<%=FilterButton.ClientID %>').click

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM