Question

I have an update panel with textbox inside it.

<asp:UpdatePanel runat="server" UpdateMode="Conditional">
     <ContentTemplate>
           <asp:TextBox runat="server" ID="txtChangeAmount" AutoPostBack="true" OnTextChanged="TxtChangeAmount_TextChanged" EnableViewState="true"></asp:TextBox>
     </ContentTemplate>
</asp:UpdatePanel>

Well, when I enter some text into the textbox, it successfully fires its OnTextChanged event as expected, but when I clear the entered text from the textbox, it causes postback properly, but the OnTextChanged event doesn't fire. I think the problem is related to ViewState. When the page loads the first time, the textbox is loaded, too, with no value in it, so there is no value stored in the ViewState for the textbox. And when I clear the textbox value, the page life cycle starts, which compares the textbox's new value with the old one, i.e the value in viewstate. Probably they are the same (null or empty) and thus OnTextChanged event doesn't fire.

How can I make the event fire in this case?

Please, pay attention to the fact, that I don't have problem with postback, but only with the event when the textbox is empty.

No correct solution

OTHER TIPS

If the UpdateMode property is set to Conditional, the UpdatePanel control's content is updated in the following circumstances:

When you call the Update method of the UpdatePanel control explicitly. When the UpdatePanel control is nested inside another UpdatePanel control, and the parent panel is updated.

When a postback is caused by a control that is defined as a trigger by using the Triggers property of the UpdatePanel control. In this scenario, the control explicitly triggers an update of the panel content. The control can be either inside or outside the UpdatePanel control that the trigger is associated with.

When the ChildrenAsTriggers property is set to true and a child control of the UpdatePanel control causes a postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control unless they are explicitly defined as triggers.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top