TextChanged事件功能无法正常工作 [英] TextChanged event function not working
问题描述
我有一个简单的aspx文件
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>
这是test4.aspx.vb code文件
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
现在的问题是,即使我键入textBox1的东西TextChanged事件,如果不触发为什么??。我应该怎么做?
Now the problem is that even if i type something in the textBox1 the textchanged event if not firing why??. What should i do??
推荐答案
您需要启用的AutoPostBack
上导致事件的文本框。
You need to enable AutoPostBack
on the textbox that results in the event.
你的问题code是它的一个服务器端事件试图调用客户端的事件。文需要在TextBox1中被输入,然后它会导致自动回发
The problem with you code is its 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>
根据您的需要,虽然。这可能是更好的来用TextBox1中使用JavaScript的价值TextBox2中。
Based on your need though. It may be better to populate the TextBox2 with the value from TextBox1 using JavaScript.
这篇关于TextChanged事件功能无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!