Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Smart Navigation not working

Status
Not open for further replies.

Eli20

Programmer
Oct 30, 2003
119
0
0
MX
hi, i have an asp.net application in c# and im setting the page navigation=true in the page directive.
It works fine in my computer, but when i run it from my clients browser, it doesnt work.

we both have winxp with ie 6.0

is there any special configuration i need to set to the browser or the firewall in order for it to work??

thank you very much

Eli

 
I am thinking the cause maybe one of the settings in IE.
It did not ever work for me on my Win2k laptop that I just retired. I tried tonight and could not figure out what in IE could cause that, though I did discover It now works for my new XP SP2 machine. I guess sadly to say it is just not that reliable. It also does not work with Firefox or Netscape.
 
After using smart navigation tonight I found some other issues.

I have a page with controls that sometimes are visible while others are not. Like a datagrid and detail table.
I turn my datagrid visible=false while editing my detail of an item. (not inline editing but a separate table)

I noticed I started getting JavaScript errors.
After viewing the source of the browser I noticed I was not looking at the actual source but a cached source that shows all of the large datagrid.
So ran in debug mode to see where the JavaScript error was and the debugger stops in the middle of some plain html rather than where it should stop in JavaScript.
I guess if you have a real simple page then use smartnav but if you run into issues like I had then you have no choice but to turn it off since you can't even see where the script error is that the smartnav is creating.
Once I turned off smartnav the strange JavaScript error was gone.

I have a work around that I have used for a while:
It looks ugly but it does works in all browsers.

easyscroll.js
Code:
window.setTimeout("StartEasyScroll(0,0)",150)
//SetEasyScroll()
var scrollt=0;
var scrolll=0;
var init_easyscroll=false

function StartEasyScroll(t2,l2){
	if(!document){window.setTimeout("StartEasyScroll()",100);return}

	if(!document.body){window.setTimeout("StartEasyScroll()",100);return}
	//alert(document.getElementById("easyscroll"))

	if(!document.getElementById("easyscroll")){window.setTimeout("StartEasyScroll()",100);return}

	var t=document.body.offsetHeight
	var l=document.body.offsetTop
	
	if(t2!=t||l2!=l){window.setTimeout("StartEasyScroll("+t+","+l+")",300);return}
	
	SetEasyScroll()
}

function SaveEasyScroll(){
	if(!init_easyscroll)return
	if(!document)return
	if(!document.body)return
	
	var t=document.body.scrollTop
	var l=document.body.scrollLeft
	
	if(t!=scrollt||l!=scrolll){
		scrollt=t;
		scrolll=l;
		setTimeout("SaveEasyScroll()",333);return
	}
	
	document.getElementById("easyscroll").value=l+','+t
return true;
}
function SetEasyScroll(){
	var arr=document.getElementById("easyscroll").value.split(",")
	
	var t=parseInt(arr[1])
	var l=parseInt(arr[0])
	
	
	document.body.scrollTop=t
	document.body.scrollLeft=l
	
	if(document.all){
		var obj = document.body;
		obj.onscroll=SaveEasyScroll
	}else{
		var obj = document.body;
		var event1 = document.createAttribute("onscroll");
		event1.nodeValue = "SaveEasyScroll()";
		obj.setAttributeNode(event1);
    }
    init_easyscroll=true
}


ASPX code behind
Code:
 Private Sub Page_PreRender1(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
        AddAutoScroll(Me)
    End Sub

Add this to your utils class
Code:
Public Sub AddAutoScroll(ByVal _Me As Object)

        Dim Context As System.Web.HttpContext = System.Web.HttpContext.Current
        Dim s As String = ""

        If _Me.Page.IsPostBack Then
            If Not Context.Request("easyscroll") = Nothing Then
                s = Context.Request("easyscroll")
            End If
        End If

        Dim hid As New Literal
        hid.Text = "<input type=hidden name=easyscroll id=easyscroll value='" & s & "'/>"

        _Me.Controls.Add(hid)

        Dim lit As New Literal
        lit.Text = "<" & "script language=javascript src=easyscroll.js></" & "script>"
        _Me.Controls.Add(lit)
    End Sub
 
Another way to do it is to set the control you want to focus to from the control that is causing the postback (the problem with this method is that if you want to do it for all controls, each control has to have a call to the function). However, it is very simple to understand and implement e.g.
Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SetFocus(Button1)
    End Sub

    Private Sub SetFocus(ByVal ctrl As Control)
        ' Define the JavaScript function for the specified control.
        Dim focusScript As String = "<script language='javascript'>" & _
          "document.getElementById('" + ctrl.ClientID & _
          "').focus();</script>"

        ' Add the JavaScript code to the page.
        Page.RegisterStartupScript("FocusScript", focusScript)
    End Sub

--------------------------------------------------------------------------------------------------------------------------------------------

Need help finding an answer?

Try the search facility ( or read FAQ222-2244 on how to get better results.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top