文本框asp.net回发在自动回发上触发两次 [英] Textbox asp.net postback trigger twice on autopostback true

查看:84
本文介绍了文本框asp.net回发在自动回发上触发两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在文本框OnTextChanged事件上,回发周期触发两次。两种方法的断点都可以理解问题。
这是我的代码示例

On textbox OnTextChanged event the postback cycle triggering twice. Breakpoints on both methods to understand the issue. Here is my code sample

<form id="form1" runat="server">
    <div>
        <asp:TextBox runat="server" ID="TextBox1" OnTextChanged="TextBox1_TextChanged" AutoPostBack="true" />
    </div>
    <asp:Label ID="Label1" runat="server"></asp:Label>
</form>

其代码落后。

     public static int cycle { get; set; }
     protected void Page_Load(object sender, EventArgs e)
     {

     }
     protected void TextBox1_TextChanged(object sender, EventArgs e)
     {
        cycle++;
        Label1.Text = cycle.ToString(); 
     }


推荐答案

避免使用AUTOPOSTBACK,请保持OnTextChanged事件陷阱
并添加一个按钮(是否隐藏)以捕获文本框
上的返回压力以产生POSTBACK。

Avoid using AUTOPOSTBACK, keep the OnTextChanged event trap and add a button (hidden or not) to catch the return pression on the textbox to produce the POSTBACK.

这里是一个例子

        <asp:Panel runat="server" CssClass="col-md-2">
            <asp:Panel runat="server" CssClass="form-group input-group" DefaultButton="BTN_Cerca">
                <span class="input-group-btn">
                    <asp:Button runat="server" ID="BTN_Cerca" Text="Codice" CssClass="btn btn-secondary" ToolTip="Cerca in magazzino"/>
                </span>
                <asp:TextBox runat="server" ID="TXT_Search" CssClass="form-control" placeholder="Numero Articolo" OnTextChanged="TXT_Search_TextChanged" />
            </asp:Panel>
        </asp:Panel>

这篇关于文本框asp.net回发在自动回发上触发两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆