Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I want to debug a textbox keyPress / keyDown event in VS2010. However, when I click a key, the function ontxtPID(event) is not fired. Did I miss something? Thanks.
ASP.NET
    <asp:TextBox ID="txtPID" ClientID="txtPID" runat="server" class="styleTextBox1" ToolTip="7 Characters, e.g. A03B001" onkeyDown="ontxtPID(event);" onkeyPress="ontxtPID(event);" MaxLength="7" MinLength="7" ></asp:TextBox>

...
    <script type="text/javascript">
        function ontxtPID(event) {
            debugger;
            var v = document.getElementById('lblWarning');
            if (v != null) {
                v.innerHTML = '';
            }

            var e1 = document.getElementById('<%=txtPID.ClientID%>').value;
            if (e1.length == 7) {
                if (event.keyCode == 13) {      // RETURN
                    event.keyCode = 9;          // TAB
                    return event.keyCode;
                }   else {
                    document.getElementById('txtPID').focus();
                }
            }
        }
    </script>
Posted
Comments
xszaboj 14-Aug-15 16:50pm    
have you tried to debug it in a browser? It is usually better than VS.

1 solution

Java
onkeyDown="ontxtPID(event)

Unless event is defined somewhere else, if likely to be undefined at time of event, thus failing before calling the function.
Replace event with a value and try again or simply remove it since the event code is probably automatic.
Java
onkeyDown="ontxtPID();"
 
Share this answer
 
v3
Comments
s yu 14-Aug-15 14:11pm    
Tried but the function is still not called. I checked other ASP.Net projects, which used to work well in JS Debugging. But now none of them is working on JS debugging. Then, I restarted my CMU, and got a warning message: the api-ms-win-crt-runtime-l1-1-0.dll is missing. Is that caused the problem? I am not sure yet. I need to repair my CPU, and then see what happens. Thanks for your response.
Patrice T 14-Aug-15 15:47pm    
That is another problem.
You need to find another computer on which you will be able to debug your older project that used to work.
Or you can post another QA with one of the project (a short one), and explain the problem.
When problem is solved on older projects, you can come back to this problem.
s yu 17-Aug-15 9:47am    
Now, I tried different browsers. If using IE and doing setup as the reference
http://www.codeproject.com/Articles/18921/Using-Visual-Studio-to-Debug-JavaScript-in-IE, debugging works. However, the debugging does not work if using Chrome or Firefox.
Patrice T 17-Aug-15 14:45pm    
I only use FireFox to debug JS and never have a problem with it, never done a special setting.
The only case where I can't debugger at runtime is when there is an error at compiletime.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


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