user1560834
user1560834

Reputation: 151

asp.net OnTextChanged not firing

I've got a few OnTextChanged events which aren't firing. The PostBack is set to true, and they're being changed (with the current date/time) from other bits in the asp.net / java code. Their values are being changed, so the events should fire but they're not:

<asp:TextBox ID="lblRoute" runat="server" AutoPostBack="true" OnTextChanged="btnRoute_Click" BorderColor="White" BorderStyle="None" ForeColor="White" Width="5px"></asp:TextBox>

As I mention, the value of this textbox is changing (and it is visible, but made to look like it isn't - it exists purely to fire it's event) but the event isn't being fired.

EDIT - just to fill in some more blanks, a user presses a button in this manner:

<button id="btnRoute" onclick="GetRoute(); return false;" runat="server" style="width: 30%">Route</button>

The button calls this, eventually (as I mention, this is being called as the label is being changed):

document.getElementById("lblRoute").value = Date.now();

Which changes the label lblRoute, which should fire our event (and yes, the called function does exist). So far it looks like I may need to change the focus, as others have said, after the label has been changed in order to fire it. Any ideas how I'd do that?

Upvotes: 1

Views: 2270

Answers (2)

Bhavesh Kachhadiya
Bhavesh Kachhadiya

Reputation: 3962

The 'OnTextChanged' event of the asp:TextBox is fired only when your textbox loses the focus.

Upvotes: 1

ElGavilan
ElGavilan

Reputation: 6904

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.textbox.textchanged(v=vs.110).aspx:

The TextChanged event is raised when the content of the text box changes between posts to the server.

The page will not post back immediately after the text is changed, but it will post back when the textbox loses focus.

Upvotes: 1

Related Questions