Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy doesn't textbox onchange event fire correctly within asp.net user control?
    primarykey
    data
    text
    <p>I have 2 textboxes that I'm trying to capture the onchange event for. These textboxes are within a user control that is within an asp.net updatepanel. Every time I change the textbox text, I receive a "Microsoft JScript runtime error: Object expected" error that doesn't provide any other helpful information.</p> <p>Here is the code:</p> <pre><code> &lt;script type="text/javascript"&gt; function ResetOrientationImage() { var width = (+document.getElementById('&lt;%= txtWidth.ClientID %&gt;').value); var height = (+document.getElementById('&lt;%= txtHeight.ClientID %&gt;').value); if (width &gt; height) { document.getElementById('&lt;%= imgOrientation.ClientID %&gt;').src = "images/buttons/Landscape.png"; } else { document.getElementById('&lt;%= imgOrientation.ClientID %&gt;').src = "images/buttons/Portrait.png"; } } &lt;/script&gt; &lt;asp:TextBox ID="txtWidth" runat="server" Width="50px" onchange="ResetOrientationImage()" Text="0"&gt;&lt;/asp:TextBox&gt; &lt;asp:TextBox ID="txtHeight" runat="server" Width="50px" onchange="ResetOrientationImage()" Text="0"&gt;&lt;/asp:TextBox&gt; &lt;asp:Image ID="imgOrientation" ImageUrl="~/images/buttons/Portrait.png" runat="server" /&gt; </code></pre> <p>I thought it must be a problem with the javascript, but I put this exact code into a standalone .aspx page and it executes correctly with no errors.</p> <p><strong>EDIT</strong> Upon looking in Firebug, the real error is that the ResetOrientationImage function cannot be found when the page executes. If I move the javascript out of the user control onto the page itself, it works as I would expect. Why can't the javascript live in the user control?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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