TextChanged event function not working

前端 未结 4 1319
萌比男神i
萌比男神i 2021-01-11 14:38

I have a simple aspx file

<%@ Page Language=\"VB\" AutoEventWireup=\"false\" CodeFile=\"test4.aspx.vb\" Inherits=\"test4\" %>



        
相关标签:
4条回答
  • 2021-01-11 14:46

    You need to enable AutoPostBack on the TextBox that results in the event.

    The problem with your code is it's a server-side event trying to invoke a client-side event. The text needs to be entered in TextBox1 and then it will result in the AutoPostBack.

    <asp:TextBox ID="TextBox1" runat="server" AutoPostBack="True"></asp:TextBox> 
    

    Based on your need though. It may be better to populate the TextBox2 with the value from TextBox1 using JavaScript.

    0 讨论(0)
  • 2021-01-11 14:54

    I know I'm late to the party with this one, but I still wanted to tell my story.

    I had a text changed event handler on a read-only TextBox.

    JavaScript changed the TextBox to read/write, but the event wouldn't fire. Probably because the back-end still thought it was read-only.

    I fixed the issue by moving all changes between R/O and R/W to the back-end. Now it works.

    0 讨论(0)
  • 2021-01-11 14:57

    Your TextBox is a server control, and text changed is a server event. It is not meant to be fired each time you type a letter, rather it is fired if the text value is different from the value at the time of the last server post back.

    If you need to run some kind of code each time a letter is pressed you will need to register and handle the client-side events OnKeyUp / OnKeyDown / OnKeyPress with VB or JavaScripting.

    0 讨论(0)
  • 2021-01-11 15:08

    On your .Aspx, add on your TextBox:

    OnTextChanged="TextBox1_TextChanged"
    
    0 讨论(0)
提交回复
热议问题