Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Make sure that jQuery is being added in the master page. Given that you have this control:</p> <pre><code>&lt;asp:Button ID="myButton" runat="server" Text="Submit" /&gt; </code></pre> <p>You can wireup the javascript with this:</p> <pre><code>$(document).ready(function() { $('[id$=myButton]').click(function() { alert('button clicked'); }); }); </code></pre> <p><code>$(document).ready()</code> fires when the DOM is fully loaded, and all the elements should be there. You can simplify this further with</p> <pre><code>$(function() {}); </code></pre> <p>The selector syntax <code>$('[id$=myButton]')</code> searches elements based on their id attribute, but matches only the end of the string. Conversely, <code>'[id^=myButton]'</code> would match the beginning, but for the purposes of filtering out the UniqueID that wouldn't be very useful. There are many many more useful selectors you can use with jQuery. <a href="http://docs.jquery.com/Selectors" rel="noreferrer">Learn them all</a>, and a lot of your work will be done for you.</p> <p>The problem is that ASP.Net creates a unique id and name attribute for each element, which makes finding them difficult. It used to be that you'd need to pass the UniqueID property to the javascript from the server, but jQuery makes that unneccessary.</p> <p>With the power of jQuery's selectors, you can decouple the javascript from the server-side altogether, and wireup events directly in your javascript code. You shouldn't have to add javascript into the markup anymore, which helps readability and makes refactoring much easier.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload