How to avoid UpdatePanel scrolling on AutoPostBack?

后端 未结 2 1479
青春惊慌失措
青春惊慌失措 2020-12-31 11:38

I have an ASP.NET FormView within an updatepanel. I\'m auto-saving the form by setting AutoPostBack=true for each of the items within the FormView.

This means the us

2条回答
  •  春和景丽
    2020-12-31 12:09

    You could bind a function that logs the current scroll position and then reapplies it after each endRequest. It might go something like this:

    // Wrap everything up for tidiness' sake
    var FormHandlerProto = function() {
        var Me = this;
    
        this.lastScrollPos = 0;
    
        this.SetupForm = function() {
            // Bind a function to the form's scroll container
            $("#ContainerId").bind("scroll", function() {
                // Record the scroll position
                Me.lastScrollPos = $(this).scrollTop();
            });
        }
    
        this.ScrollForm = function() {
            // Apply the last scroll position
            $("#ContainerId").scrollTop(Me.lastScrollPos);
        }
    
        this.EndRequestHandler = function(sender, args) {
            if (args.get_error() != undefined)
                Me.ScrollForm();
            }
        }
    }
    
    var FormHandler = new FormHandlerProto();
    FormHandler.Setup(); // This assumes your scroll container doesn't get updated on postback.  If it does, you'll want to call it in the EndRequestHandler.
    
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(FormHandler.EndRequestHandler);
    

提交回复
热议问题