Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7522807
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:37:16+00:00 2026-05-30T02:37:16+00:00

I have 2 textboxes that I’m trying to capture the onchange event for. These

  • 0

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.

Here is the code:

    <script type="text/javascript">
        function ResetOrientationImage() {
            var width = (+document.getElementById('<%= txtWidth.ClientID %>').value);
            var height = (+document.getElementById('<%= txtHeight.ClientID %>').value);
            if (width > height) {
                document.getElementById('<%= imgOrientation.ClientID %>').src = "images/buttons/Landscape.png";
            } else {
                document.getElementById('<%= imgOrientation.ClientID %>').src = "images/buttons/Portrait.png";
            }
        }
</script>
<asp:TextBox ID="txtWidth" runat="server" Width="50px" onchange="ResetOrientationImage()" Text="0"></asp:TextBox>
<asp:TextBox ID="txtHeight" runat="server" Width="50px" onchange="ResetOrientationImage()" Text="0"></asp:TextBox>
<asp:Image ID="imgOrientation" ImageUrl="~/images/buttons/Portrait.png" runat="server" />

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.

EDIT
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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T02:37:18+00:00Added an answer on May 30, 2026 at 2:37 am

    I stumbled upon this question which gave me my answer:

    Javascript object "is not defined" error after ScriptManager.RegisterClientScriptInclude

    I moved my javascript function into an external file and referenced it in the user control code behind like this:

        ScriptManager sm = ScriptManager.GetCurrent(Page);
        ScriptReference sr = new ScriptReference("~/scripts/ResetOrientationImage.js");
        if (!sm.Scripts.Contains(sr))
           sm.Scripts.Add(sr);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an asp.net 3.5 update panel and I have a few textboxes that
I am using ASP.NET MVC 3. I have textboxes and I have a control
I have several textboxes that are added dynamically after an ajax call. These boxes
I'm trying to select all the textboxes that have the class foo. Doing: console.log(
I have a view based application which has some textboxes that I'm trying to
this is a CSS / design question. I have three textboxes that i want
I have 3 WPF TextBoxes that have segments of the URL. I want to
probably a simple one, have a dozen textboxes that each contain one character. i'm
Forms http://img101.imageshack.us/img101/6970/stackoverflowquestion.png I have 2 input textboxes that take a host or IP. When
I have textboxes being generated by a repeater that use OnTextChanged with autopostback enabled

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.