0

First of all it does work as a regular button:

<input type="button" value="Block" id="btnBlock" name="btnBlock"/>

But I need to work on an asp:button as well, I've tried this:

<asp:Button ID="btnBlock" runat="server" Text="Block" OnClientClick="btnClick"/>

But it doesn't work, just sends a JS error (edited):

Microsoft JScript runtime error: 'btnBlock' is undefined

My JS blockUI function:

<script language="javascript" type="text/javascript">
$(document).ready(function() {
   $('#btnBlock').click(function() {
        $.blockUI({ message: $('#myForm') });
    });
});
</script>

I've also tried changing the blockUI function to this, but it doesn't seem to work, it doesn't recognize the asp code inside the script:

<script language="javascript" type="text/javascript">
$(document).ready(function() {
   $('#<%= btnBlock.ClientID %>').click(function() {
        $.blockUI({ message: $('#myForm') });
    });
});
</script>
user1676874
  • 875
  • 2
  • 24
  • 45
  • Are you sure the error is there because your error says 'btnClick' is undefined, not 'btnBlock' is undefined. Also, if the last didn't work, it should say 'ct100_clientplaceholder_btnBlock is undefined' (something like that). – Brian Mains Jan 07 '13 at 19:43
  • Sorry I was trying with different functions at the time, I changed it back to btnBlock and still gives me the same error. – user1676874 Jan 07 '13 at 19:49

1 Answers1

0

In your asp button markup you've got

OnClientClick="btnClick"

This sets the client-side script that executes when a Button control's Click event is raised. That is the fired event looks for a javascript function called btnClick. The issue is that you are wiring the click event via jQuery $(selector).click(someFunction); and also in the OnClientClick event.

Change the asp button control to remove the OnClientClick event:

<asp:Button ID="btnBlock" runat="server" Text="Block" />

Keeping the javascript the same.

heads5150
  • 7,263
  • 3
  • 26
  • 34