JavaScript Reference with Master Pages

Posted on 2009-02-21
Last Modified: 2012-05-06
So, I'm still figuring out this JavaScript stuff.

Referencing another question, code posted below.

What if my imgCtrl is on a page that uses the MasterPage, and my JavaScript is on the MasterPage? Is there any way to reference it in that manner?

<script type="text/javascript">

   var imgControlId = "<%= imgCtrl.ClientID %>";



in your javascript function


image = document.getElementById(imgControlId);

image.href = url;

Open in new window

Question by:veruthandai
    1 Comment
    LVL 12

    Accepted Solution

    Sure you can reference the control in page that user MasterPage and you can place the javascript in the MasterPage.  The only thing is both should have the same path.  If it isn't then, have the javascript in the Content page inside the content tag, as there will be issue loading the .js file if the content page is located in another folder.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
    ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now