文本框更改事件 [英] text box change event

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

问题描述

我有成员ID文本框,并且成员具有名称和ID的下拉列表

我的功能是,在查询dropdpwn之后,我需要调用dropdown_selected更改事件.

以同样的方式,当用户在文本框中输入成员ID时,我需要触发文本框更改事件以进一步检查,下拉列表中是否包含该值(ID).

i have member id text box and member drop down with name and ID

i have a fuctionality that when after binging dropdpwn i need to call dropdown_selected change event.

in same way when user enter member id in text box i need fire text box change event to check wherther ,drop down contains that value(ID) or not.

推荐答案

有一个TextBox1_TextChanged事件.
There is a TextBox1_TextChanged event for this.
<asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True" ontextchanged="TextBox1_TextChanged"></asp:TextBox>


protected void TextBox1_TextChanged(object sender, EventArgs e)
{
    //do something.
}



这将使页面回发,并且代码将在服务器上执行.

如果不需要服务器端处理,建议使用JavaScript.
您可以在文本框中添加onblur事件,然后调用JavaScript函数进行所需的验证.



This will let the page post back and the code will be executed on the server.

If you do not need server side processing, using JavaScript is recommended.
You can add an onblur event to the textbox and call a JavaScript function to do the required validation.

<asp:TextBox ID="TextBox1" runat="server" onblur="return ValidateDDL();"></asp:TextBox>


function ValidateDDL()
{
    if(document.getElementById("<%= DropDownList1.ClientID %>").value == document.getElementById("<%= TextBox1.ClientID %>").value)
    {
        alert("cannot be duplicate");
        return false;
    }
    return true;
}



希望这会有所帮助!



Hope this helps!


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

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