TextChanged event function not working

I have a simple aspx file

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="test4.aspx.vb" Inherits="test4" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <body> <form id="form1" runat="server"> <div id="content"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> </div> </form> </body> </html> 

And this is the test4.aspx.vb code file

 Partial Class test4 Inherits System.Web.UI.Page Protected Sub TextBox1_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged TextBox2.Text = TextBox1.Text End Sub End Class 

Now the problem is that even if I introduce something into the textBox1 event with the changed text, if I don’t shoot, why ??. What should I do?

+8
source share
4 answers

You need to enable AutoPostBack in the TextBox, which will result in an event.

The problem with your code is a server event trying to raise an event on the client side. The text must be entered in TextBox1 , and then this will lead to AutoPostBack .

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

Based on your need. It might be better to populate TextBox2 value from TextBox1 using JavaScript.

+23
source share

Your TextBox is a server control, and text modified is a server event. It should not be launched every time you enter a message, but it works if the text value differs from the value during the last server message.

If you need to run some code each time you press a letter, you will need to register and process events on the client side of OnKeyUp / OnKeyDown / OnKeyPress using VB or JavaScripting.

+3
source share

In your .Aspx, add to your TextBox:

 OnTextChanged="TextBox1_TextChanged" 
+1
source share

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

I had a text handler handler with a read-only text field.

JavaScript changed the TextBox to read / write, but the event did not fire. Perhaps because in the background it was still believed that it was read-only.

I fixed the problem by moving all changes between R / O and R / W to the internal server. Now it works.

0
source share

All Articles