Click here to Skip to main content
11,575,635 members (61,741 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET Javascript
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...
Posted 6-Sep-11 21:10pm
Edited 8-Sep-11 5:05am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
MrProgrammer_78 at 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 at 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
rajeevtechnical at 7-Sep-11 5:34am
This I believe should work.
MrProgrammer_78 at 7-Sep-11 5:58am
Not help also
Elina Blank at 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 at 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
MrProgrammer_78 at 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 at 8-Sep-11 17:17pm
This may be a caching issue
MrProgrammer_78 at 8-Sep-11 21:59pm
how to prevent this caching issue ???
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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!

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

but all not help also.
Morgs Morgan at 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()
MrProgrammer_78 at 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?
MrProgrammer_78 at 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?
MrProgrammer_78 at 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 at 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

Advertise | Privacy | Mobile
Web03 | 2.8.150624.2 | Last Updated 8 Sep 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100