Please can you help!
I have a web application that uses javascript to create a scroll bar effect for my gridview but also maintains scroll position in certain circumstances. The maintain scroll position is triggered based on the value of a session variable called "shouldscroll". I am using Page Init event to add the maintain scroll position functionaility to the scroll event. I am using Visual Web Developer 2005 and VB.
This works fine when all of the code (VB parts and javascript) are all in one aspx page but I run into problems when I try to use a Master Page and Content Page. The scroll effect still works but I can no longer get the maintain scroll position functionality to work. Can anyone help with this? Below is some of the relevant code, sorry it's so long if I can provide it to anyone in any better way please let me know:
MASTER PAGE:
I'm not sure whether perhaps having changed the value of "shouldscroll" to Yes in the GridView1_RowCommand above in the content page whether it needs to somehow call the javascript function again from the Master Page?
Something I've noticed about the code aswell is that in order to assign the onscroll event in Page init to the GridViewScrollSalesDetails2, I have to put runat="server" within the <div> tag surrounding the Gridview being affected (when it was in a normal aspx page). When using Master Pages and Content pages I can't use runat="server" in the content page as this causes the scroll facility to not appear at all. I have therefore put the runat="server" in the <div> tag surrounding the contentplace holder instead - not sure if this is correct but it doesn't work anyway.
Just to re-iterate I can get the scroll effect to work between Master page and Content Page but not the maintain scroll position part of it.
Does anybody know what I'm doing wrong and if this is even possible. Maybe I have to revert back to a normal aspx page for the pages affected by this but this means duplicating code!!!
Thanks
Steven
I have a web application that uses javascript to create a scroll bar effect for my gridview but also maintains scroll position in certain circumstances. The maintain scroll position is triggered based on the value of a session variable called "shouldscroll". I am using Page Init event to add the maintain scroll position functionaility to the scroll event. I am using Visual Web Developer 2005 and VB.
This works fine when all of the code (VB parts and javascript) are all in one aspx page but I run into problems when I try to use a Master Page and Content Page. The scroll effect still works but I can no longer get the maintain scroll position functionality to work. Can anyone help with this? Below is some of the relevant code, sorry it's so long if I can provide it to anyone in any better way please let me know:
MASTER PAGE:
Code:
Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs)
Me.GridViewScrollSalesDetails2.Attributes.Add("onscroll", "javascript:setscrollPos();")
End Sub
<style type="text/css">
#GridViewScrollSalesDetails2
{
width: 73%; height: 100px; overflow: auto; margin-left: 5px;
} div#GridViewScrollSalesDetails2 table th
{
width: 100px;
} #GridViewScrollSalesDetails2 th
{
top: expression(document.getElementById( "GridViewScrollSalesDetails2" ).scrollTop-2);
z-index: 20;
} #GridViewScrollSalesDetails2 td.locked, #GridViewScrollSaleDetails2 th.locked
{
left: expression(document.getElementById( "GridViewScrollSalesDetails2" ).scrollLeft);
position: relative; z-index: 100; border: solid 1px white;
}
#GridViewScrollSalesDetails2 th, #GridViewScrollSalesDetails2 th.locked
{
position: relative; cursor: default; border: solid 1px white;
}
#GridViewScrollSalesDetails2 th.locked
{
z-index: 110;
}
</style>
<script type="text/javascript">
<!--window.onload = function ()
{
var shouldScroll = '<%= session("shouldScroll") %>';
if ( shouldScroll.toUpperCase() != 'YES' )
return;
var strCook = document.cookie;
if ( strCook.indexOf("!~") !=0 )
{
var intS = strCook.indexOf("!~");
var intE = strCook.indexOf("~!");
var strPos = strCook.substring(intS+2, intE);
document.body.scrollTop = strPos;
}
// This condition will set scroll position od <div>.
if ( strCook.indexOf("!*") != 0 )
{
var intdS = strCook.indexOf("!*");
var intdE = strCook.indexOf("*!");
var strdPos = strCook.substring(intdS+2,intdE);
document.getElementById('GridViewScrollSalesDetails2').scrollTop = strdPos;
}
}
function setScrollPosition()
{
var intY = document.body.scrollTop;
document.cookie = "yPos=!~" + intY + "~!";
}
window.onscroll = setScrollPosition;
function setScrollPos()
{
var divY = document.getElementById('GridViewScrollSalesDetails2').scrollTop;
document.cookie = "divPos=!*" + divY + "*!";
}
// -->
</script>
<form id="form1" runat="server">
<div id="GridViewScrollSalesDetails2" runat="server">
<br />
<asp:contentplaceholder id="ContentPlaceHolder1" runat="server" >
</asp:contentplaceholder>
<br />
</div>
</form>
CONTENT PAGE:
<div id="GridViewScrollSalesDetails2">
<asp:GridView............ </GridView>
</div>
Protected Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Edit" Then
Session("shouldScroll") = "YES"
Else
End If
I'm not sure whether perhaps having changed the value of "shouldscroll" to Yes in the GridView1_RowCommand above in the content page whether it needs to somehow call the javascript function again from the Master Page?
Something I've noticed about the code aswell is that in order to assign the onscroll event in Page init to the GridViewScrollSalesDetails2, I have to put runat="server" within the <div> tag surrounding the Gridview being affected (when it was in a normal aspx page). When using Master Pages and Content pages I can't use runat="server" in the content page as this causes the scroll facility to not appear at all. I have therefore put the runat="server" in the <div> tag surrounding the contentplace holder instead - not sure if this is correct but it doesn't work anyway.
Just to re-iterate I can get the scroll effect to work between Master page and Content Page but not the maintain scroll position part of it.
Does anybody know what I'm doing wrong and if this is even possible. Maybe I have to revert back to a normal aspx page for the pages affected by this but this means duplicating code!!!
Thanks
Steven