Introduction
This article describes how to Disable the Back button in IE Browser and the scroll position of a Web page is maintained after postback.
Usally all the controls in Asp.net use runat server so it will postback for every action . while refreshing , the scroll bar again goes to top position of the browser. To avoid this problem use
Page.MaintainScrollPositionOnPostBack
property is TRUE.
Navigation Tip 1:
As already explained use the Page.MaintainScrollPositionOnPostBack property in Page load event it will maintain the scroll positioin while postback.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Page.MaintainScrollPositionOnPostBack = True
Catch ex As Exception
Throw ex
End Try
End Sub
Navigation Tip 2:
Use <code>Page.SetFocus
(eg:) If the Login is invalid then its easy to focus the cursor to user name.
</code />
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
'To Maintain the focus for the Control
Page.SetFocus(Control)
Catch ex As Exception
Throw ex
End Try
End Sub//
Navigation Tip 3:
Usually the web browser cache all the pages in the history so the client can able to navigate to previous page using the Back button to avoid this problem use "no-cache" in your page to resitrict the end user to navigate to Previous page.
And also we can use <code>location.replace
//
//
// To Disable the Back Button using Response.CacheControl//
<%
Response.Buffer = True
Response.Expires = 0
Response.ExpiresAbsolute = Now() - 1
Response.CacheControl = "no-cache"
%>//
//
// To Disable the Back Button using Java Script//
<script language="JavaScript">
<!--// Method 1
javascript:window.history.forward(1);
// Method 2
javascript:location.replace(this.href);
//-->
</script>//
A brief desciption of how to use the article or code. The class names, the methods and properties, any tricks or tips.
Remember to set the Language of your code snippet using the Language dropdown.
Use the "var" button to to wrap Variable or class names in <code> tags like this
.
:
method or
window.history.forward(1)
to avoid the same.Property to Maintain the focus for a given control while postback. you can use this property in Login Form to set focus.