Lee
Lee

Reputation: 8734

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.

Upvotes: 1

Views: 266

Answers (3)

KP.
KP.

Reputation: 13730

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();
    });

});

Upvotes: 1

Kundan Singh Chouhan
Kundan Singh Chouhan

Reputation: 14292

Try this

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

Upvotes: 3

Mark Adesina Omoniyi
Mark Adesina Omoniyi

Reputation: 449

Change

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

to

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

Upvotes: 0

Related Questions