|
The root cause of these issues is derived from the way an UpdatePanel is refreshed on partial postback. When
an ASP.NET page receives the result of a partial postback, it clears out the current content on the UpdatePanel
and resets the inner HTML to a newly received result. All of the DOM objects within the UpdatePanel are destroyed
and recreated, resulting in the loss of focus and data.
The best solution, of course, is to avoid postbacks in the first place. However, there are times when developers
use postbacks for convenience instead of business logic. If the business logic of the postbacks requires no new
data from database, (i.e., all information is already available on the client-side), then it can and should be handled
with client-side JavaScript code.
However, if new data is required, there is an alternative solution in PageMethods, which is used by Iron Speed Designer’s
popup text and image. PageMethods sends to and receives from the server much less data than partial postbacks. They apply
the results to existing DOM objects instead of destroying and recreating them, thus preserving the focus and data.
If the two solutions above are not applicable to your page and postback is your only option, there is not much you can do
to prevent data loss. The best you can do is to make the server process as fast as possible. However, you can prevent focus
loss, or more precisely, restore focus with some JavaScript code.
|