473,385 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

javascript within asp.net framework, document.getElementbyId error

69
hi guys,

here is my problem. i have a js function called changemsg that takes a label in an aspx page and sets its text to blank.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript" >
  2.         function changemsg(lbl){
  3.             document.getElementById(lbl).innerHTML=" ";
  4.         }
  5. </script>
  6.  
on the page load method of my page, i call the function as follows
Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2.     {
  3.         if (!IsPostBack)
  4.         {
  5.             manuTextBox.Attributes.Add("onFocus", "changemsg('ctl00_ContentPlaceHolder1_manuLabel');");
  6.             wcTextBox.Attributes.Add("onFocus", "changemsg('ctl00_ContentPlaceHolder1_wcLabel');");
  7.             vmTextBox.Attributes.Add("onFocus", "changemsg('ctl00_ContentPlaceHolder1_descLabel');");
  8.  
  9.         }
  10.     }
  11.  
i am using master pages, that is why i am saying 'ctl00_ContentPlaceHolder1_descLabel' instead of plain descLabel etc.
Also, it is worth noting that i am calling the same function with different labels.

my problem is that if i Enable script Debugging in internet explorer, when the page loads, the message is
"document.getElementById(...)' is null or not an object"

even if i disable script Debugging in internet explorer, the status bar would say "done but with errors" and that is the error behind it

how can i fix the problem
is my code correct?
Jun 3 '08 #1
3 1661
gits
5,390 Expert Mod 4TB
please have a look at or post the generated html-code ... and check whether the ids are correct or not ... or give a link to a testpage.

kind regards
Jun 3 '08 #2
phpmel
69
thank you for you suggestion,

i did view the generated source code and what i discovered was that there was no code for the labels since i had initially set them to be NOT visible, so when the page is loaded it was causing the error. i set the labels visible=true and i believe it is working now.

thank you so much. i am going to play around with it a little bit and if anything else occurs, i will post back

thank you again
Jun 3 '08 #3
gits
5,390 Expert Mod 4TB
no problem ... ;) post back when you have more problems with it ...

kind regards
Jun 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.