How to make an ASP.NET TextBox fire it's onTextChanged event fire in an AJAX UpdatePanel?

后端 未结 4 1014
慢半拍i
慢半拍i 2020-12-01 21:54

I am trying to get an textBox to fire it\'s onTextChanged event every time a keystroke is made rather than only firing only when it loses focus. I thought that adding the As

相关标签:
4条回答
  • 2020-12-01 22:13

    All the AsyncPostBackTrigger does is make sure only that portion of the page refreshes when the event is fired, it does not change when the event is fired.

    I think it's possible to do what you want, but you'd need to write some javascript code to manually fire the event... and I don't even want to think about making that work.

    0 讨论(0)
  • 2020-12-01 22:19
    • You need to call the _postback() function for your textbox control when the onkeyup is raised using javascript.
    • However, since your textbox is inside your update panel, the textbox will get re-rendered everytime the user hits a key, causing the cursor to loose focus.
    • This will not be usable unless you get your textbox out of the the updatepanel. That may work out for you, as update panels tend to be a bit slow, you may still have usability issues. - I would suggest using an autocomplete component.

    P.S : there is one in the asp.net control toolkit or you could use the jquery autocomplete plugin which I have found to be a bit better.

    0 讨论(0)
  • 2020-12-01 22:26

    AutoPostBack="true" OnTextChanged="TextBox1_TextChanged"

    Both events are required to trigger text change event.

    0 讨论(0)
  • 2020-12-01 22:29

    Dont Need use AJAX controls for checking the availability.. Its is not Compulsory to use it AJAX Controls.. We can use the Following Code..

    <iframe>
    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="true" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
    
     protected void TextBox1_TextChanged(object sender, EventArgs e)
        {
            RequiredFieldValidator1.ErrorMessage = "";
            Label1.Text = "";
            string name = TextBox1.Text.ToString();
            string constr = "data Source=MURALY-PC\\SQLEXPRESS; database=Online; Integrated Security=SSPI";
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            string query = "select UserName from User_tab where UserName='" + name + "'";
            SqlCommand cmd = new SqlCommand(query, con);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
    
                Label1.Text = "UserName Already Exists";
            }
            else
            {
                Label1.Text = "";
                Label1.Text = "UserName Available";
            }
            con.Close();
    
    
        }
    </iframe>
    
    0 讨论(0)
提交回复
热议问题