Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>EDIT</strong></p> <p>As @Adam points out in the comments, there is a native jQuery mechanism that basically does the same thing as the hack in my original answer. Using jQuery you can do</p> <pre><code> $('[id$=myButton]').click(function(){ alert('button clicked'); }); </code></pre> <p>My hack was originally developed as a Prototype work around for ASP.NET and I adapted it for the original answer. Note that jQuery basically does the same thing under the hood. I recommend using the jQuery way, though, over implementing my hack.</p> <p><strong>Original answer left for comment context</strong></p> <p>When you use a master page, ASP.NET mangles the names of the controls on the dependent pages. You'll need to figure out a way to find the right control to add the handler to (assuming you're adding the handler with javascript).</p> <p>I use this function to do that:</p> <pre><code>function asp$( id, tagName ) { var idRegexp = new RegExp( id + '$', 'i' ); var tags = new Array(); if (tagName) { tags = document.getElementsByTagName( tagName ); } else { tags = document.getElementsByName( id ); } var control = null; for (var i = 0; i &lt; tags.length; ++i) { var ctl = tags[i]; if (idRegexp.test(ctl.id)) { control = ctl; break; } } if (control) { return $(control.id); } else { return null; } } </code></pre> <p>Then you can do something like:</p> <pre><code>jQuery(asp$('myButton','input')).click ( function() { alert('button clicked'); } ); </code></pre> <p>where you have the following on your child page</p> <pre><code>&lt;asp:Button ID="myButton" runat="server" Text="Click Me" /&gt; </code></pre>
 

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