Click here to Skip to main content
Click here to Skip to main content
Go to top

Navigation Tips in Asp.net

, 21 Sep 2007
Rate this:
Please Sign up or sign in to vote.
This article explains how to Disable the Back button and fix the scroll bar while postback

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.

//

//
// To Maintain the Scroll bar Position
//

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 />
//

//
// To Maintain the focus for the Control//

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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Thirumal S
Web Developer
India India
No Biography provided

Comments and Discussions

 
GeneralMaintainScrollPositionOnPostBack PinmemberBrent Lamborn5-Aug-07 7:57 
GeneralRe: MaintainScrollPositionOnPostBack PinmemberThirumal S5-Aug-07 18:30 
GeneralHi thirumal Pinmembergaya_moni3-Aug-07 22:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140926.1 | Last Updated 21 Sep 2007
Article Copyright 2007 by Thirumal S
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid