Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JQuery / ASP.NET newbie questions about <asp:Button>

Hey all, having an issue getting asp buttons to interact with JQuery. I'm basically trying to hide a div that contains a form and replace it with an processing image. It works fine for me when I use an HTML input button as the trigger but when I use an aspButton nothing happens.

This works (the id of the HTML button is 'btnSubmit'):

<script>
    $('#btnSubmit').click(function () {
        $('#form1').fadeOut('fast', function () {
            $('#processing').fadeIn('fast', function () {
            });
        });
    });
</script>

This doesn't (the id of the ASP button is 'btnSubmitASP'):

<script>
    $('#btnSubmitASP').click(function () {
        $('#form1').fadeOut('fast', function () {
            $('#processing').fadeIn('fast', function () {
            });
        });
    });
</script>

Any idea what the trick is to get the asp button to do this?

Thanks

like image 514
markiyanm Avatar asked Dec 12 '25 04:12

markiyanm


2 Answers

The ASP.net server ID for the control is different from the html ID. (ASP.net calls this the client ID). You can get the client id this way:

$('#<%= this.btnSubmitASP.ClientID %>').click( /* etc */ );
like image 162
recursive Avatar answered Dec 14 '25 20:12

recursive


If you are using asp.net 4.0 you can set the button's ClientIDMode property ='Static'. This will stop the runtime from mucking with the ID.

like image 44
DancesWithBamboo Avatar answered Dec 14 '25 19:12

DancesWithBamboo