Bad Choices

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

A few weeks ago, we had a problem with pages blanking when doing a response.redirect. This only occurred when smartnavigation was on. So we tried to use server.transfer, and now there are session variables disappearing. At the unload of one page, the session variable is set and shows up when debugging. But on the load of the page that we just transferred to the session variable we just set comes up as 'nothing'

So far the bad choices are
1. Redirect with smartnavigation on - no redirect, current page just blanks out
2. Redirect without smartnavigation - redirects, but longer pages jump to the top at every postback (users complain
3. Server.Transfer - allows smartnavigation, but loses session variables causing program crashes. It doesn't matter whether preserve is true or not

Are these problems with the framework? Have they been addressed? Have they been fixed? Is there a work around for any of these problems? We are using 1.1. We need smartnavigation on, to redirect or transfer to another page AND to keep the values of the session variables that we set.
 
If you are just using the SmartNav to keep the pages at the same scroll
position I suggest you ditch SmartNav and go with a client side solution. I
actually took some code and put it in a custom control one before to
accomplish with ease. Then all we had to do was drag and drop the control on
any pages. I have copies and pasted the control code to this message. Feel
free to use it.

Code:
Imports System

Imports System.Text

Imports System.Web

Imports System.Web.UI

Imports System.Web.UI.HtmlControls

'''=====================================================

'''Written by Stanley Glass Jr on 2/4/04

'''This control will keep the scroll position the same on postbacks.

'''This is accomplished by having two hiddne fields that keep track of

'''the X and Y positions of the scroll bars and some javascript to scroll
the

'''page back to the last known position.

'''=====================================================



<ToolboxData("<{0}:PageScroll runat=server />")> _

Public Class PageScroll

Inherits Control

Private SaveScriptName As String = "StaticPostBackScrollPositionSave"

Private LoadScriptName As String = "StaticPostBackScrollPositionLoad"

Private VerticalPositionFieldName As String =
"StaticPostBackScrollVerticalPosition"

Private HorizontalPositionFieldName As String =
"StaticPostBackScrollHorizontalPosition"

Private ScriptHiddenField As String = "document.forms[0].{0}.value"

Private ScriptGetPositionLine As String = ScriptHiddenField + " =
(navigator.appName == 'Netscape') ? window.page{1}Offset :
document.body.scroll{2};"



Private Function GetSavePositionScript() As String

Dim sb As New StringBuilder

sb.Append("<script language=""JavaScript""> " + ControlChars.Lf)

sb.Append("function SaveScrollPositions() { " + ControlChars.Lf)

sb.AppendFormat(ScriptGetPositionLine, VerticalPositionFieldName, "Y",
"Top")

sb.AppendFormat(ScriptGetPositionLine, HorizontalPositionFieldName, "X",
"Left")

sb.Append("setTimeout('SaveScrollPositions()', 10);")

sb.Append("} " + ControlChars.Lf)

sb.Append("SaveScrollPositions(); " + ControlChars.Lf)

sb.Append("</script> " + ControlChars.Lf)

Return sb.ToString()

End Function 'GetSavePositionScript



Private Function GetLoadPositionScript() As String

Dim sb As New StringBuilder

Dim script As String = [String].Format("scrollTo({0},{1}); " +
ControlChars.Lf, [String].Format(ScriptHiddenField,
HorizontalPositionFieldName), [String].Format(ScriptHiddenField,
VerticalPositionFieldName))

sb.Append("<script language=""JavaScript""> " + ControlChars.Lf)

sb.Append("function RestoreScrollPosition() { " + ControlChars.Lf)

sb.AppendFormat("scrollTo({0},{1}); " + ControlChars.Lf,
Page.Request(HorizontalPositionFieldName),
Page.Request(VerticalPositionFieldName))

sb.Append("} " + ControlChars.Lf + " window.onload = RestoreScrollPosition;
" + ControlChars.Lf)

sb.Append("</script>")

Return sb.ToString()

End Function 'GetLoadPositionScript



Protected Overrides Sub OnPreRender(ByVal e As EventArgs)

If Page.IsPostBack And Not Page.IsStartupScriptRegistered(LoadScriptName)
Then

Page.RegisterClientScriptBlock(LoadScriptName, GetLoadPositionScript())

End If

If Not Page.IsStartupScriptRegistered(SaveScriptName) Then

Page.RegisterClientScriptBlock(SaveScriptName, GetSavePositionScript())

Page.RegisterHiddenField(VerticalPositionFieldName, [String].Empty)

Page.RegisterHiddenField(HorizontalPositionFieldName, [String].Empty)

End If

End Sub 'OnPreRender



Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)

End Sub 'Render

End Class 'StaticPostBackPosition
Tobe said:
A few weeks ago, we had a problem with pages blanking when doing a
response.redirect. This only occurred when smartnavigation was on. So we
tried to use server.transfer, and now there are session variables
disappearing. At the unload of one page, the session variable is set and
shows up when debugging. But on the load of the page that we just
transferred to the session variable we just set comes up as 'nothing'.
So far the bad choices are:
1. Redirect with smartnavigation on - no redirect, current page just blanks out.
2. Redirect without smartnavigation - redirects, but longer pages jump to
the top at every postback (users complain)
3. Server.Transfer - allows smartnavigation, but loses session variables
causing program crashes. It doesn't matter whether preserve is true or not.
Are these problems with the framework? Have they been addressed? Have
they been fixed? Is there a work around for any of these problems? We are
using 1.1. We need smartnavigation on, to redirect or transfer to another
page AND to keep the values of the session variables that we set.
 
Back
Top