Error: 'keyCode' is null or not an object
<p>I am getting this error when i run this function</p>

<pre><code>&lt;script language="javascript" type="text/javascript"&gt;
        //function for check digit
    function check_no(e)
         {
             if (!((e.keyCode &gt;= 48) &amp;&amp; (e.keyCode &lt;= 53)))
             {
                 alert("Solo valores entre 0 y 5 pueden ser ingresados");
                 e.keyCode = 0;
             }
         }
&lt;/script&gt;
</code></pre>

<p>I call the function in my load page in c#</p>

<pre><code>foreach (GridViewRow grdrow in DGPlanilla.Rows)
                {
                    TextBox tb1 = (TextBox)grdrow.FindControl("TextBox1");
                    if (tb1 != null)
                    {
                        tb1.Attributes.Add("Onkeypress", "check_no()");
                    }

                }
</code></pre>
