当前位置: 动力学知识库 > 问答 > 编程问答 >

Setting text on label by javascript

问题描述:

Please help me with this.

I have a function on my page to be called by the AjaxAsyncFileupload control.

 function uploadComplete1(sender, args) {

var file1 = new String(args.filename).toLowerCase();

if (file1.indexOf('docx', file1.length - 4) == -1 && file1.indexOf('doc', file1.length - 3) == -1 && file1.indexOf('xlsx', file1.length - 4) == -1 && file1.indexOf('xls', file1.length - 3) == -1) {

var elem = document.getElementById("ct100_ContentPlaceHolder1_lblUploadedFile1Minor_Network_Change");

elem.InnerHTML = 'This file is not allowed.'; elem.style.visibility = "visible";

}

}

When this function is called, I get an error: "Unhandled exception: Cannot set property InnerHTML of null"

I cann't find out why I get this error. The label it needs to set the text of, is on the page. I even took the exact name via chrome-pageinspect to make sure I have the right name.

This script is put in the page via code behind after the label has been added to the controls of the page.

What am I doing wrong here?

网友答案:

check your "elem" is not null when you set innerHTML

分享给朋友:
您可能感兴趣的文章:
随机阅读: