ckhsu:
Is this because the javascript code is placed on the master page and the control is on another page?
yes
If you are generating your javascript on your master page and TextBox1 represents a control on your content page, then you cannot directly reference TextBox1.
From a design standpoint, its not a good idea for your master page to know much about the content page(s) it is associated with. If your master page only works correctly with a content page that contains a TextBox specifically named TextBox1, then you really havent created a clear seperation between your master and content pages. Instead you have coupled them tightly together and unnecessary coupling is something to be avoided.
If the textbox is a control on the content page, then the content page should be responsible for injecting any script for that textbox.
with that said, the way to find a control on the content page from the master page would go something like this:
document.getElementbyId('<%=Me.FindControl("ContentPlaceHolder1").FindControl("TextBox1").ClientId%>');
Me represents the master page
Then we find the contentplaceholder with represents the content page
Then we can find the textbox that on the content page that was placed inside the master page.