jQuery Trigger .NET Event


InterServer Web Hosting and VPS
Sony Playstation PS4 Pro Custom Build NVMe SSD Drive - Enclosure case and Crucial NVMe SSD
PS4 Pro Custom External SSD NVMe Drive

How I built a PS4 Pro Custom External SSD NVMe Drive...

NUC8i7BEH with memory
Intel NUC8I7BEH Review and Custom Build

This is my review of the Intel NUC8i7BEH and a summary of my build...

Card image cap
Asus M5A88-M EVO Review

This is my review of the Asus M5A88-M EVO motherboard...

Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit
Corsair Vengeance Blue Review

This is my review of the Corsair Vengeance Blue 8GB (2x4GB) DDR3 PC3-12800C9 1600MHz Dual Channel Kit memory...

Robotic Arm with USB PC Interface Review
Robotic Arm with USB PC Interface Review

This is my review of the Robotic Arm with USB PC Interface...

jQuery Trigger .NET Event

Here we look at how to use jQuery to trigger an ASP.NET Event.

Well it's possible to use to jQuery code to trigger ASP.NET events from the client side, such as the Click event of an ASP.NET Button.

You need to know the client ID of the ASP.NET control, so the .NET 4.0 feature of being able to control the client ID comes in extra handy, specifically the 'Static' setting which allows one to control the exact client ID of the ASP.NET control. Ensuring you haven't duplicated the id elsewhere, you can specify unique ids for your controls manually, making finding the control with jQuery alot easier than with the automatically generated ids which ASP.NET creates when using a mode other than 'static'.

Trigger ASP.NET Button Click Event

Once we have the client ID of the ASP.NET control, we can then use jQuery to target that control with a selector and then simply calling .trigger() we can specify the event from ASP.NET which we want, such as in the following example:


$('#MarsButton').trigger('click');


jQuery Trigger .NET Event Example

Here is a full example of how to call an ASP.NET Button's server Click event using jQuery.


<script type="text/javascript">

    $(document).ready(function () {
        $('#HTML_Mars').click(function () {
            $('#MarsButton').trigger('click');
        });
    });

</script>


Sponsored Links
SolarSystem - AngularJS Demo
SolarSystem - Angular JS Demo

Check out my first Angular JS demo hosted in Azure, it helped win my first Angular contract. Put the sound on.