Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
grid, aspx, C#

I am getting this JavaScript runtime error: Unable to get property 'scrollIntoView' of undefined or null reference. Line 4 is where it throw the error.

<script>

01 function ScrollIntoView()
02 {
03 var gridView = document.getElementById ('ct100_ContentPlaceHolder1_gvRptItems_BranchChief_With_Focus');
04 gridView.scrollIntroView((Window.name * (window.innerHeight)));
}

</script>

The code does exist.

C#
public static void FocusControlOnPageLoad(string ClientID,
                                      System.Web.UI.Page page)
       {

           page.RegisterClientScriptBlock("CtrlFocus",

           @"<script>

              function GetDivPosition()
               {
                   document.getElementById('GVWF').scrollTop = window.name;
                   //--alert(numericPostion) FOR TESTING ONLY!!!
               }

               function ScrollIntoView()
               {
                 var gridView = document.getElementById('ctl00_ContentPlaceHolder1_gvRptItems_BranchChief_With_Focus');
                 gridView.scrollIntoView((window.name * (window.innerHeight)));
               }

               function RunScripts()
               {
                   ScrollIntoView();
                   GetDivPosition();
               }

             window.onload = RunScripts;

             </script>");
       }

9
Posted
Updated 22-Sep-15 8:31am
v2
Comments
Richard Deeming 22-Sep-15 14:17pm    
The error is pretty clear - your page doesn't contain an element with the ID ct100_ContentPlaceHolder1_gvRptItems_BranchChief_With_Focus.

Use the correct ID, and test whether the gridView variable actually contains something before trying to call a method on it.
Member 11227881 22-Sep-15 14:54pm    
public static void FocusControlOnPageLoad(string ClientID,
System.Web.UI.Page page)
{

page.RegisterClientScriptBlock("CtrlFocus",

@"<script>

function GetDivPosition()
{
document.getElementById('GVWF').scrollTop = window.name;
//--alert(numericPostion) FOR TESTING ONLY!!!
}

function ScrollIntoView()
{
var gridView = document.getElementById('ctl00_ContentPlaceHolder1_gvRptItems_BranchChief_With_Focus');
gridView.scrollIntoView((window.name * (window.innerHeight)));
}

function RunScripts()
{
ScrollIntoView();
GetDivPosition();
}

window.onload = RunScripts;

</script>");
}
Richard Deeming 22-Sep-15 15:00pm    
So now, not only are you trying to call a method on an element that doesn't exist in your document, you're trying to multiply a string (window.name) by a number (window.innerHeight)!

Use the correct ID, test whether the gridView variable contains something before calling a method on it, and don't try to multiply a string by a number!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900