I was recently building a website for work, and I thought it would be cool to have the page 'remember' where the scroll position was when a postback was performed. I had set the flag in the web.config file, and forgot about it.
Awhile later I added a web service to the project, went to debug it in a browser, and got the following message:
The MaintainScrollPositionOnPostback page directive cannot be set without an htmlform.
I resolved the issue with the following steps:
- Remove the web.config maintainScrollPositionOnPostBack flag.
- Create a base page that inherites from System.Web.UI.Page
- Set maintainScrollPositionOnPostBack programmatically in the base page.
- Force all pages to inherit from the base page by setting the pageBaseType attribute for the Pages element in the web.config.
Base page code:
Public
Class BasePage : Inherits Page
Private
Sub Page_Init(ByVal sender As
Object, ByVal e As System.EventArgs) Handles
Me.Init
If
Not Page.Request.FilePath.EndsWith("asmx") Then
MyBase.MaintainScrollPositionOnPostBack = True
End
If
End
Sub
End
Class