• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1360
  • Last Modified:

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

0
SaraDob
Asked:
SaraDob
  • 4
  • 3
1 Solution
 
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
 
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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
 
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:
good job...

cheers...
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now