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 : http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23914095.html

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;
        }
        else
        {
        return true;
 
        }
 
    }
 
    </script>
 
'this is how the textbox is :
 <asp:TextBox ID="txtActivityCode" runat="server" Onkeypress= "return ValidateTxtarea()" MaxLength="3"></asp:TextBox>

Open in new window

LVL 1
SaraDobAsked:
Who is Participating?
 
SaraDobAuthor Commented:
I found outwhy its not working. silemone..
I had to use:
getelementBYId instead of getelementid...
Thanks again for looking into this
 
 
0
 
silemoneCommented:
can you try to use something like this:

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

0
 
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?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
silemoneCommented:
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...

second,
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...

0
 
silemoneCommented:
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...
0
 
SaraDobAuthor Commented:
Silemone,
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');
        alert(elem.value);  
Because of this manipulation of textboxe names, i have used
document.getElementid('<%=txtActivityCode.ClientID%>')
Any lead!!!!!!
0
 
silemoneCommented:
good job...

cheers...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.