简体   繁体   English

ASP更新面板不起作用

[英]ASP Update Panel Not Working

I Have the following ASP Panel 我有以下ASP面板

<asp:UpdatePanel ID = "UpdatePanel1" runat = "server">
      <ContentTemplate>
            <asp:TextBox ID="txtNumber" runat="server" ToolTip="The Assignment's Number" ValidationGroup="updateAssignment" AutoPostBack="True" ontextchanged="txtNumber_TextChanged"></asp:TextBox>

      </ContentTemplate>
</asp:UpdatePanel>

The Script Manager is also present but the page is still doing a postback. 脚本管理器也存在,但页面仍在回发。 The thing is in other pages it does not happen. 事情在其他页面上没有发生。 I tried adding a trigger to the update panel with the control being the textbox but it still does a Postback. 我尝试将触发器添加到更新面板,控件为文本框,但仍执行回发。 Please Help me Out. 请帮帮我。

First of all, serverside code not client side code. 首先,服务器端代码不是客户端代码。 The textchanged event is much different then js onchange event. textchanged事件与js onchange事件大不相同。 This code fires when you lose focus. 当您失去焦点时,此代码将触发。 You need to set autopostback to true on the textbox but include it as a trigger: 您需要在文本框上将autopostback设置为true,但将其包括为触发器:

 <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="TextBox1" AutoPostBack="true" runat="server" ontextchanged="TextBox1_TextChanged"></asp:TextBox>
        </ContentTemplate>
        <Triggers>
        <asp:AsyncPostBackTrigger ControlID="TextBox1" />
        </Triggers>
        </asp:UpdatePanel>

As you noticed just setting the textbox to Autopostback=true will not work, outside of the UpdatePanel it will cause a postback. 如您所见,仅将文本框设置为Autopostback=true将不起作用,在UpdatePanel外部将导致回发。 However, if wrap it around an updatepanel and specify AsyncPostBackTrigger and assign the ControlID to the textbox in question it will work for you. 但是,如果将其包裹在updatepanel上并指定AsyncPostBackTrigger并将ControlID分配给有问题的文本框,它将对您ControlID I have just tested this in chrome and IE and it works. 我刚刚在chrome和IE中对此进行了测试,并且可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM