ASP.Net文本框onblur事件 [英] ASP.Net textbox onblur event

查看:598
本文介绍了ASP.Net文本框onblur事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框,其值我需要验证(如果文本框的值是50,则显示lblShowMsg消息)当用户切换到该文本框(onBlur事件)的。我似乎无法得到正确的语法

I have a textbox, whose values I need to validate (if value of textbox is 50, then display message in lblShowMsg) when the user tabs out of the textbox (onBlur event). I can't seem to get the syntax right.

我有我的页面加载事件代码:

I have this code on my pageload event:

protected void Page_Load(object sender, EventArgs e)
{
    txtCategory.Attributes.Add("onblur", "validate()"); 

}



但我似乎无法得到javascript代码正确。 ?任何建议

But I can't seem to get the javascript code correct. Any suggestions?

推荐答案

在后面的代码:(VB.NET)

In the Code behind: (VB.NET)

在页面加载事件

txtAccountNumber.Attributes["onBlur"] = "IsAccNumberValid(" & txtAccountNumber.ClientID & ")";



在哪里txtAccountNumber是在标记网页的文本框的ID和你通过文本框因为客户端ID JavaScript是客户端而不是服务器端。而现在在标记页面(的.aspx)有这样的javascript在页面的头部分:

Where txtAccountNumber is the ID of the TextBox in the markup page and you pass the ClientID of the textbox because JavaScript is client side not server side. And now in the markup page(.aspx) have this javascript in the head section of the page:

<script type="text/javascript">                     
function IsAccNumberValid(txtAccountNumber) {                                             
    if (txtAccountNumber.value.length < 6) {    
                      alert(txtAccountNumber.value);
            }    
        }    
</script>

这篇关于ASP.Net文本框onblur事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆