Question

Could someone help please, i'm stuck on the following error:

'document.Form1.imgLoading' is null or not an object control.js, line 55 character 2

Which is:

Line 55: document.Form1.imgLoading.style.width=370

From:

function setLoading(){
    var strPath = "../images/"
    var strFName = "searchingText.gif"
    var strSearchPath = ""

    //15/2if (!document.Form1.TextBoxLangID.value == "") { //SO LANG USED
    //  strSearchPath = strPath + document.Form1.TextBoxLangID.value + "/brand/" + strFName
    //}
    //else{
    //  strSearchPath = strPath +  "brand/" + strFName
    //15/2}

    //document.Form1.imgSearchingText.src = strSearchPath
    document.Form1.imgLoading.style.width=370
    document.Form1.imgLoading.style.height=328
    document.Form1.imgLoading.style.left = 327
    document.Form1.imgLoading.style.top = 220
    document.Form1.imgLoading.style.zIndex=2000'
Was it helpful?

Solution

The problem with your code is you are referring like form.controlname. In ASP.Net the control names are generated like ctl$imgLoading etc based on Master page/nested control configuration.

Better avoid document.Form1.imgLoading and make use of referring it based on id using native document.getElementById()

If you have the script code in .aspx page, Please use the below code to refer the element

var imgLoading=document.getElementById('<%= imgLoading.ClientID %>');
imgLoading.style.width=370;

In case if you have the script in JS file Make sure you set the ClientIDMode=staticSupported from ASP.Net 4.0 only for imgLoading control in .aspx page, then

var imgLoading=document.getElementById('imgLoading');
imgLoading.style.width=370;

OTHER TIPS

I do not have enough reputation to comment, but I just want to say that if your <script> tags are in the <head> section, place your script tags at the back of the body section, or load the script onload of the document.

This is because the image that is in the <body> section of your document has yet to be loaded, so it is null or not an object.

Hope that helps.

If imgLoading is a asp:Image control then you have to find it using next code:

document.getElementById('<%= imgLoading.ClientID %>').style.width = 370
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top