Click here to Skip to main content
15,883,928 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 asp.net page i write that:

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


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


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:
JavaScript
page.getElementById("diTextArea").innerHTML=html_code;




realy i tired...
Posted
Updated 8-Sep-11 5:05am
v7

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.
 
Share this answer
 
Comments
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    
document.getElementById("MainPlaceHolder_OperatorPlaceHolder_diTextArea").innerHTML=wysiwyg_code;
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
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:
HTML
<system.web>
     <pages clientidmode="Static"></pages>
</system.web>


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

Goodluck
 
Share this answer
 
Comments
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:
clientIDMode,ClientIDMode,clientIdMode,clientIdmode,clientIDmode...etc

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()
{
$('.div1').html('wysiwyg_code');
}
</script>
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?

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



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