Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# TextChanged在回发时再次触发事件_C#_Asp.net_Visual Studio_Updatepanel - Fatal编程技术网

C# TextChanged在回发时再次触发事件

C# TextChanged在回发时再次触发事件,c#,asp.net,visual-studio,updatepanel,C#,Asp.net,Visual Studio,Updatepanel,这就是ASPX的基本外观。当我离开(tab)txt1时,调用TextChanged事件,它通常填充txt2。但是,当我在txt2中更改文本并点击btnSave更新此数据时,会再次调用txt1\u TextChanged(在实际的btnSave\u点击方法触发之前)

这就是ASPX的基本外观。当我离开(tab)
txt1
时,调用
TextChanged
事件,它通常填充
txt2
。但是,当我在
txt2
中更改文本并点击
btnSave
更新此数据时,会再次调用
txt1\u TextChanged
(在实际的
btnSave\u点击
方法触发之前)

<

  • 将您的示例UpdatePanel放入一个新项目(并添加ScriptManager)
  • 添加以下方法

    <asp:UpdatePanel ID="uppBaixa" runat="server">
        <ContentTemplate>
                <asp:TextBox ID="txt1" runat="server" AutoPostBack="true" OnTextChanged="txt1_TextChanged"></asp:TextBox>
                <asp:TextBox ID="txt2" runat="server"></asp:TextBox>
                <asp:Button ID="btnSave" runat="server" OnClick="btnSave_Click" />
        </ContentTemplate>
    </asp:UpdatePanel>
    
  • 将txt1更新为ABC,则txt2将成为ABC

  • 将txt2更新为Bar,然后更新txt1。文本将为ABC,txt2将为Bar
  • 按Save只会将txt1更改为Foo,txt将保留在工具栏上
这意味着你所描述的不会重现

请注意,即使在服务器端设置
txt1.text=“foo”
,它也不会引发
textChanged
事件,这意味着它可能在客户端发生

请尝试将此添加到
页面加载事件中以查找它

protected void btnSave_Click(object sender, EventArgs e)
{
    this.txt1.Text = "foo";

}
protected void txt1_TextChanged(object sender, EventArgs e)
{
    txt2.Text = txt1.Text;
}

对不起。代码正在运行(至少是我提到的部分),我只是没有把它放在这里。。我试着在这里发布这个“伪”代码,看看是否有人有这种问题
  this.btnSave.Attributes.Add("OnClick", "debugger");