Javascript : not working even with <%=textbox1.Clientid">, when included in masterpage

Hi all,
Hope to get few answers thsi time atlease. I have been posting questions, but failed to get even a comment for this :

But the real question for this post is here: I have included my content page with the masterpage.
i have a textbox.The user is not supposed to enter more than 3 chars. I have set the maxlength of the textbox=3.
But i also want to alert the user " cannot enter more than 3 chars". I call a javascript function. It was all working fine as an individual .Aspx page.
now i have included that in a master page. Now the above said error come, when i try to enter  anything in that textbox.Here is piece of code.
Plase help..Hope to get answers SOON
'This is the javascript code
<asp:Content ID="ContProduct" ContentPlaceHolderID="MainContent" Runat="Server">
   <script type="text/javascript" >
    function ValidateTxtarea()
    if (document.getElementid('<%=txtActivityCode.ClientID%>').value.length >= 3) 
        alert('Activity Code Cannot be more than 3 Chars')
        return false;
        return true;
'this is how the textbox is :
 <asp:TextBox ID="txtActivityCode" runat="server" Onkeypress= "return ValidateTxtarea()" MaxLength="3"></asp:TextBox>

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

can you try to use something like this:

var elem = document.getElementid('<%=txtActivityCode.ClientID%>');
alert(elem.value); <-- debug the value

SaraDobAuthor Commented:
Thnaks for quick reply.You have solved soo many of my problems..hoping to get this done ASAP.
I tried the code you suggested...Nope still the same problem. I get the error " Object or method not found.
But i get a build error as "OnKeypress"  of textbox is outdated. I dont think it will be the problem because, on key press, the javascript function is being called.Will that keypress make a difference?
ok...for the first problem...

what environment are you using?  vs2005?  

try this:  under Tool of IE window--> Select Internet Options -->Select Advanced Tab --> Uncheck Disable Script Debugging (in IE)...
This may give you a better error and specific line where the error is occurring if you're using vs2005...which I assume because in vs2008 you can actually debug javascript...

If you don't have the right event name in your tags, it will give you errors, but the javascript method name can be similar...

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

also, when you load the page, you can actually look at view source and get the correct name for the control.  The source will show modified name due to it being in master page...
SaraDobAuthor Commented:
i'm using VS2008.
I had already unchecked the script debugging.
When i view source i get this in javascript:
 var elem = document.getElementid('ctl00_MainContent_txtActivityCode');
Because of this manipulation of textboxe names, i have used
Any lead!!!!!!
SaraDobAuthor Commented:
I found outwhy its not working. silemone..
I had to use:
getelementBYId instead of getelementid...
Thanks again for looking into this

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
good job...

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.