How to avoid UpdatePanel scrolling on AutoPostBack?

后端 未结 2 1467
青春惊慌失措
青春惊慌失措 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:06

    Simply put the Timer control within the content template.

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <asp:Timer ID="Timer1" runat="server" Interval="5000" OnTick="Timer1_Tick">
    </asp:Timer>
    <asp:ImageButton ID="ImageButton1" runat="server" Height="350" Width="700" />
    </ContentTemplate>
    </asp:UpdatePanel>
    
    0 讨论(0)
  • 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);
    
    0 讨论(0)
提交回复
热议问题