Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
In my aspx file,

I tried to retrieve the control values, e.g. using the piece of code below:
JavaScript
function onChange_Dept() {
    debugger;
    var v1 = document.getElementById('<%=TextBoxLastName%>').value;
    var v2 = document.getElementById('<%=TextBoxEmail.ClientID%>').value;
}

When I run debugging, the dynamic code is show below
JavaScript
function onChange_Dept() {
    debugger;
    var v1 = document.getElementById('System.Web.UI.WebControls.TextBox').value;
    var v2 = document.getElementById('ctl00_ContentPlaceHolder1_TextBoxEmail').value;
}

where the v1 is null, and v2 returns value correctly. I don't know why in the dynamic code, the TextBoxLastName is not accessed correctly.
ASP.NET
The 2 controls in the aspx look like below:
<pre lang="HTML">
<td class="stylecol2" colspan="2">
   <asp:TextBox ID="TextBoxLastName" runat="server" class="styleTxtbox" ToolTip="Requester's Last Name"></asp:TextBox>
</td>
...
<td colspan="3" style="height: 29px">
  <asp:TextBox ID="TextBoxEmail" runat="server" class="styleTxtbox"  ontextchanged="TextBoxEmail_TextChanged" ></asp:TextBox>
  <asp:RegularExpressionValidator ID="validateEmail1" runat="server" ControlToValidate="TextBoxEMail" ErrorMessage="Invalid email" ValidationExpression="^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$" ForeColor="#FF3300"></asp:RegularExpressionValidator>
</td> 
</pre>

I don't know why the 2 controls behave differently in dynamic debugging. Wish you can help me for this answer. Thanks.

What I have tried:

Got problem in JavaScript debugging and unknown why
Posted
Updated 4-Mar-16 8:32am

1 solution

You missed out the .ClientID change

var v1 = document.getElementById('<%=TextBoxLastName%>').value;


to

var v1 = document.getElementById('<%=TextBoxLastName.ClientID%>').value;
 
Share this answer
 
Comments
s yu 4-Mar-16 15:04pm    
Thanks for you to detect my low-lever and stupid mistake.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900