ASP: ontextchanged not firing

僤鯓⒐⒋嵵緔 提交于 2020-01-25 04:22:12

问题


Note: I am brand new at ASP.NET. I'm actually going to training on Monday, but we have a hot project that required me to dive in and get done as much as I can.

I've got a textbox on my page, and I would like it to call an event on the server whenever it is changed. I don't care if "changed" means changed and loses focus, or just whenever a keyup happens. Either case will work.

The issue is that, for some reason, whenever I change my textbox and then remove focus, the server-side method is not getting called. Viewing through the debugger in Chrome, I don't even see any sort of AJAX call being made that would inform the server that a textbox was changed.

My Code:

ASCX File

    <asp:UpdatePanel ID="UpdatePanel2" runat="server">
        <ContentTemplate>
            <asp:TextBox ID="tempTagBuilder" runat="server" 
                CssClass="depBuilder_tempTagBuilder" 
                ontextchanged="tempTagBuilder_TextChanged" AutoPostBack="True"></asp:TextBox>
        </ContentTemplate>
    </asp:UpdatePanel>

ASCX.cs File

    //whenever the text is changed
    protected void tempTagBuilder_TextChanged(object sender, EventArgs e)
    {
        System.Diagnostics.Debug.WriteLine("Hit");
    }

Anyone have a good idea of what my issue might be?

Update 1:

I got it working (somewhat). I had to go into the updatepanel's properties and add the textchanged event to the triggers collection. However, now whenever it sends the update it is emptying out the other textboxes on my page!


回答1:


It doesn't fire because it's in an update panel most likely. Seems the updatepanel requires you to set a trigger for the event.

Problem with textbox inside updatepanel - not causing OnTextChanged event



来源:https://stackoverflow.com/questions/9229790/asp-ontextchanged-not-firing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!