admin管理员组文章数量:1419215
I am getting this error when i run this function
<script language="javascript" type="text/javascript">
//function for check digit
function check_no(e)
{
if (!((e.keyCode >= 48) && (e.keyCode <= 53)))
{
alert("Solo valores entre 0 y 5 pueden ser ingresados");
e.keyCode = 0;
}
}
</script>
I call the function in my load page in c#
foreach (GridViewRow grdrow in DGPlanilla.Rows)
{
TextBox tb1 = (TextBox)grdrow.FindControl("TextBox1");
if (tb1 != null)
{
tb1.Attributes.Add("Onkeypress", "check_no()");
}
}
I am getting this error when i run this function
<script language="javascript" type="text/javascript">
//function for check digit
function check_no(e)
{
if (!((e.keyCode >= 48) && (e.keyCode <= 53)))
{
alert("Solo valores entre 0 y 5 pueden ser ingresados");
e.keyCode = 0;
}
}
</script>
I call the function in my load page in c#
foreach (GridViewRow grdrow in DGPlanilla.Rows)
{
TextBox tb1 = (TextBox)grdrow.FindControl("TextBox1");
if (tb1 != null)
{
tb1.Attributes.Add("Onkeypress", "check_no()");
}
}
Share
Improve this question
edited Jul 9, 2009 at 23:03
Steve Harrison
126k17 gold badges89 silver badges72 bronze badges
asked Jul 9, 2009 at 22:48
Gilberto MunozGilberto Munoz
2 Answers
Reset to default 5The problem with the snippet you've pasted, is that the javascript function expects a single argument e, which you've not supplied. Your e actually needs to be the window.event property for this call to work.
You have two options. Either rewrite your function to be:
function check_no() {
if (!((window.event.keyCode >= 48) ... some other stuff
}
OR, rewrite the calling code to be
foreach (GridViewRow grdrow in DGPlanilla.Rows)
{
TextBox tb1 = (TextBox)grdrow.FindControl("TextBox1");
if (tb1 != null) { tb1.Attributes.Add("Onkeypress", "check_no(window.event)");
}
You are expecting e to be passed into the function, which it will in FireFox et al. but not in IE. You need to normalize your event object.
function check_no(e) {
e = e || window.event;
if (!(e.keyCode >= 48) {
... some other stuff
}
}
本文标签: cError 39keyCode39 is null or not an objectStack Overflow
版权声明:本文标题:c# - Error: 'keyCode' is null or not an object - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745290900a2651787.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论