Wednesday, March 28, 2012

Postback sees TextChanged event while timer initiated the postback


Hi,

I have a challenge which I cannot seem to master and I hope that somebody already solved it.

Here is the setup to create the issue:

Place an updatepanel on a page, place a timer control inside (or outside with a trigger section for the panel), set the interval to 3000 or so and enable the timer.

Then place a TextBox on the page and add some code to the TextChanged event.

Now start the page..

Type some text in the textbox but don't press enter, when the timer fires you will find that the TextChanged event comes in through the postback.

I think I have tried everything, partialrendering to true, updatemode to conditional, childelementsastriggers to false and so on...

I need the text entered in the textbox to stay as it is until the moment the user presses enter, while the update panel constantly refreshes a datagrid.

Does anybody have a solution? Would I need to use a javascript timer which updates the datagrid? would that prevent a postback?

Please help...

Thanks

Is the textbox inside the updatepanel?

If your expecting the user to hit enter, presumably that triggers a click event for a button. Why not read/process the textbox's value as part of the button's click event and avoid TextChanged altogether?


Inside or outside renders the same problem.

The thing is that when a user enters some text in the textbox but is not finished typing yet, the timer causes a postback which in turn results in the TextChanged event, but the user is not ready to post yet.


Yeah i'd say this is by design and theres nothing you can do about it. Modify your approach so it doesn't make use of the TextChanged event (as i suggested in previous post).


If you can put the DataGrid and TextBox in separate UpdatePanels, that would begin to solve the problem.


Ha, I won't sacrefice design over some "feature". I won't believe that this behaviour is by design and if it is then there must be a way to intercept the event..

Hmm... I may have solved my own problem.

P.S. the TextChanged event is needed as we are using barcode scanners which add a carriage return to the end of the text stream which triggers the TextChanged event just nicely. The user should also be able to enter some code without hitting a button as confirmation..

Thanks,

Wouter


I'm not sure how multiple UpdatePanels would change your design, since you didn't post any sample code.

You may want to take a closer look at how UpdatePanels work. What you're describing is the inevitable consequence of putting a timer on an UpdatePanel that contains data entry fields.

No comments:

Post a Comment