简体   繁体   中英

Textbox on TextChanged event giving error!

I have a textbox in my webpage and I want to fire as soon User clicks or enter something on this textbox. Code is working but it is firing when an User hits Enter button. I want it to fire when user types their 1st character. Which event is app for this?

This is my mockup code:

<asp:TextBox ID="txtAgentName" runat="server" OnTextChanged = "txtAgentName_TextChanged"></asp:TextBox>

But when I am running this webpage it is showing me this err:

CS0123: No overload for 'txtAgentName_TextChanged' matches delegate 'System.EventHandler'

I have this on my code behind:

  protected virtual void txtAgentName_TextChanged(object sender, EventArgs e)
    {

    }

Made a breakpoint in in here, and seems like it is firing when I am hitting Enter button. I want to fire when user enter 1st character inside that textbox.

What I am doing wrong here?

your event handler must have this signature

protected void txtAgentName_TextChanged(object sender, EventArgs e)
{
   ...
}

does it?

使用javascript的TextBox1.Attributes.Add("OnKeyPress", "GetKeyPress()") ,然后根据需要回发。

<%@ Page Language="C#" %>
<script runat="server">
    protected void txtSearch_TextChanged(object sender, EventArgs e)
    {
        lblSearchResults.Text = "Search for: " + txtSearch.Text;
    }
</script>
<html>
<head>
    <title>TextBox AutoPostBack</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

    <asp:Label
        id="lblSearch"
        Text="Search:"
        Runat="server" />
    <asp:TextBox
        id="txtSearch"
        AutoPostBack="true"
        OnTextChanged="txtSearch_TextChanged"
        Runat="server" />

    <hr />

    <asp:Label
        id="lblSearchResults"
        Runat="server" />

    </div>
    </form>
</body>
</html>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM