getElementById(...)为null或不是对象 [英] getElementById(...) is null or not an object

查看:84
本文介绍了getElementById(...)为null或不是对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在ASP.NET项目中使用Javascript,
Javascript代码在单独的文件中,在asp.net页面中,我这样写:

Hi guys,

I am using Javascript in ASP.NET project,
Javascript code is in separate file and in asp.net page i write that:

<script type="text/javascript" src="js/myfile_settings.js"></script>


<div id="diTextArea">
                    <script type="text/javascript" >
                     initiate(window.document);
                    </script>
</div>



ASP.NET页是母版页内的内容页

js文件中的初始化方法用于在div控件中注入或呈现html代码.

当我运行项目时,出现此错误:

getElementById(...)为null或不是对象.

我制作了一个小项目,并使用了js文件,相同的html代码和母版页,并且运行成功.
但是在我的大项目中,它无法成功运行.

两个项目,相同的js文件和html代码之间没有区别,但是一个项目有很多页面,另一个项目是一个页面.

js文件具有以下方法:



ASP.NET page is content page inside master page

initiate method in js file is used to inject or render html code within the div control.

When i run the project that error appear:

getElementById(...) is null or not an object.

I make small project and used the js file and the same html code and master page and it run successfully.
but in my big project it is not run successfully.

no difference between two project, the same js file and html code but one has many pages and the other is one.

js file has this method:

page.getElementById("diTextArea").innerHTML=html_code;





真的很累...





realy i tired...

推荐答案

检查您要传递给getElementById的控件名称. getElementByID,除了作为控制名称的参数之外,它区分大小写,因此请检查一下.如果您的aspx页是母版页的内容页,那么您的控件ID也会附加在母版页ID中
因此,请转到页面,然后右键单击获取页面的视图源,复制控制的ID并将其粘贴到Java脚本中.
check your control name which you are passing to getElementById. getElementByID except a paramenter as control name which is case sensitive so please check that. if your aspx page is content page of master page then your control id will append the master page id also
so please go to the page and then right click get viewsource of page copy the id of the contol and paste it in java script.



提交给客户端时,看到您正在使用母版页和内容页,则ASP.NET可能会更改您的控件名称.

将您的webconfig更改为包括:
Hi,
There could be a chance that your control names are being changed by ASP.NET when submitted to the client-side seeing that you are using master and content pages.

Change your webconfig to include:
<system.web>
     <pages clientidmode="Static"></pages>
</system.web>



这样asp.net不会弄乱您的控件ID!

祝你好运



that way asp.net will not mess with your control ids!

Goodluck


这篇关于getElementById(...)为null或不是对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆