Keep the position of the scroll bar on the page so that the scroll bar is still in the original position after the page is submitted
In general, many people use page. smartnavigation = false to control the browser's scroll bar. For the scroll bar control of DIV in the page, I am readingCodeAnd write one for your reference only:
Public shared sub savedivscrollposition (byval dividarray as string, byval objpage as page)
Dim savescrollposition as string
Dim I as integer
Dim divid () as string
Divid = dividarray. Split (",")
For I = 0 to divid. Length-1
Objpage. registerhiddenfield (divid (I) & "_ scrollpos", objpage. Request. Form (divid (I) & "_ scrollpos "))
Savescrollposition = "<script language = 'javascript '> "_
& "Function savescrollposition (){"_
& "If (document. All ['" & divid (I) & "']! = Undefined ){"_
& "Document. Forms [0]." & divid (I) & "_ scrollpos. value = "_
& "Document. All ['" & divid (I) & "']. scrolltop + ','"_
& "+ Document. All ['" & divid (I) & "']. scrollleft ;}}"_
& "If (document. All ['" & divid (I) & "']! = Undefined) {document. All ['"& divid (I) &"']. onscroll = savescrollposition ;}"_
& "</SCRIPT>"
Objpage. registerstartupscript ("savescroll" & divid (I), savescrollposition)
Next
End sub
Public shared sub restoredivscrollposition (byval dividarray as string, byval objpage as page)
Dim restorescrollposition as string
Dim setpositionfunction as string
Dim I as integer
Dim divid () as string
Divid = dividarray. Split (",")
For I = 0 to divid. Length-1
Setpositionfunction = setpositionfunction & "setscrollposition ('" & divid (I )&"');"
Next
Restorescrollposition = "<script language = 'javascript '> "_
& Setpositionfunction _
& "</SCRIPT>"
Objpage. registerstartupscript ("restorescroll", restorescrollposition)
End sub
Javascript:
Function setscrollposition (divid ){
VaR E;
VaR;
VaR OBJ;
If (document. getelementbyid (divid )){
OBJ = eval ('document. Forms [0]. '+ divid +' _ scrollpos ');
If (OBJ ){
E = eval ('document. Forms [0]. '+ divid +' _ scrollpos '). value;
A = E. Split (',');
Document. getelementbyid (divid). scrolltop = A [0];
Document. getelementbyid (divid). scrollleft = A [1];
}
}
}
When calling the page in the background, write the following code:
Private sub page_load (byval sender as system. Object, byval e as system. eventargs) handles mybase. Load
Call savedivscrollposition ("div1, div2, div3", me)
Call restoredivscrollposition ("div1, div2, div3", me)
End sub
sorry, you can write one sub for your reference only.