Click here to Skip to main content
14,767,619 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

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

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

<div id="diTextArea">
                    <script type="text/javascript" >

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:

realy i tired...
Updated 8-Sep-11 6:05am

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.
MrLonely_2 7-Sep-11 3:54am
Thanks man,yes my aspx page is content page of master page,
and i did what u told me and the same problem still,
that is the id i copy it from view source of page "MainPlaceHolder_OperatorPlaceHolder_diTextArea"
I try every thing but no way
pooja 08 7-Sep-11 4:59am
instead of page try with document.form.getElementById and 1st keep one alert box before assigning any value to that control check document.form.getElementById (your controlid) &check what you are getting
Geekian_senate 7-Sep-11 5:34am
This I believe should work.
MrLonely_2 7-Sep-11 5:58am
Not help also
Elina Blank 8-Sep-11 17:16pm
To be sure what the id of the control is, do "View Source" and find that element. Then do "document.getElementById()" with passing exactly the id you saw in the View Source
pooja 08 7-Sep-11 6:14am
did you placed alert box?
& check what it is showing?
Is it showing null or object?
if it is showing object then problem is in other place?
reply what you are getting
MrLonely_2 7-Sep-11 8:01am
It give me Null,
i put that in js fie:
//alert("dsfgsdfg"); it is as comment

the first line i mark it as comment for put your alert statement,
but when run it still give me the first alert ??????

I think that Visual Studio 2005 which i use is itself cause the problem
i think i must upgrade to Visual Studio 2008 or 2010,
is it true ?
Elina Blank 8-Sep-11 17:17pm
This may be a caching issue
MrLonely_2 8-Sep-11 21:59pm
how to prevent this caching issue ???
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:
     <pages clientidmode="Static"></pages>

that way will not mess with your control ids!

MrLonely_2 7-Sep-11 5:58am
I include it but it give me error that:
Unrecognized attribute 'clientidmode'
Morgs Morgan 7-Sep-11 6:01am
Sorry about that, it's case sensitive so go like so:
<pages clientIDMode="Static"></pages>
MrLonely_2 7-Sep-11 6:04am
I know it case sentive man, so i try every like:

but all not help also.
Morgs Morgan 7-Sep-11 6:13am
What .Net framework are u using? this property is only supported in .Net 4.
if you are using anything less than 4 then try accessing your controls by their class names using jQuery e.g.

<div class="div1" önclick="SetInnerHtml();"></div>
<script type="text/javascript" >
function SetInnerHtml()
MrLonely_2 7-Sep-11 6:13am
I am using ASP.NET 2.
I think this attribute clientIDMode is used is ASP.NET 4,
is it right?
MrLonely_2 7-Sep-11 6:17am
at the same moment hhhhh,
thank man, i appreciate your help,
but i do not know jquary, can i use class by javascript?
MrLonely_2 7-Sep-11 6:30am
I change my initiate method to return variable wysiwyg_code that represent html code,
This is my try :

<div class="div1" ></div>
<script type="text/javascript" >
function SetInnerHtml()
but not worked with me.
I do not want to render the html code within div when click it but when page loaded,
can u adjust my JQuary code please as i do not know JQuary.
thank you
Morgs Morgan 7-Sep-11 6:33am
send me an e-mail and attach your test.aspx page and your myfile_settings.js file then i can help u maybe.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900