Introduction
Its an updated version of the control provided at this link "http://www.codeproject.com/aspnet/lili.asp" by "Ibrahim ULUDAG". I really appreciate his work.
SmartNavigationFixupModule is an easy to use custom control.
When we set SmartNavigation = true for a web page we (in fact i have faced) face following two major issues:
- Popup window that i open in my form, is minimized.
- When I try to setfocus to control programatically it enters into an infinite loop.
The control provided in the above link worked only on submit buttons, I updated that to capture the scroll event of the window.
How this control works?
The control actually stores the scroll position of the web page before postback, and brings the user back to that position when page is reloaded after postback.
The control creates two hidden variables on the form when it is rendered.
writer.Write("<input type=\"hidden\" id=\"" + this.ID + "_OffsetY\" name=\"" + this.ID + "_OffsetY\" value=\"0\">\n");
writer.Write("<input type=\"hidden\" id=\"" + this.ID + "_OffsetX\" name=\"" + this.ID + "_OffsetX\" value=\"0\">\n");
It attaches the scrolling functions to the page's onscroll. (Rest you can remove from the code available with the article.)
When page is loaded after postback. Following code fragment of the control gets executed:
if (Page.IsPostBack )
{
writer.Write("function " + this.ID + "_OnLoad(){\n");
writer.Write("var xVal = " + Page.Request.Form[this.ID + "_OffsetX"] + ";\n");
writer.Write("var yVal = " + Page.Request.Form[this.ID + "_OffsetY"] + ";\n");
writer.Write("window.scrollTo(xVal,yVal);\n");
writer.Write("}\n");
writer.Write("if (!isIE){\n");
writer.Write("window.addEventListener('load'," + this.ID + "_OnLoad, false);\n");
writer.Write("}\n");
writer.Write("else{\n");
writer.Write("window.attachEvent('onload'," + this.ID + "_OnLoad);\n");
writer.Write("}\n");
How to use it?
SmartNavigationFixupModule control is very easy to use. It being a custom control, you just need to add it to the toolbox. Drag the control and place it on the web page. No coding is required, rest of the things will be handled by the control .