Microsoft JScript runtime error: "null" is null or not an object

I have an application, for example, where I can create dynamic tabs. and remove the crossbar option on the tabs. When I try to delete a tab, I get an error like

Microsoft JScript runtime error: "null" is null or not an object and points to my Javascript code.

Here is my JS code.

<script type="text/javascript"> /* <![CDATA[ */ function deleteTab(tabText) { var tabStrip = $find("<%= RadTabStrip1.ClientID %>"); var multiPage = $find("<%= RadMultiPage1.ClientID %>"); var tab = tabStrip.findTabByText(tabText); var pageView = tab.get_pageView(); var tabToSelect = tab.get_nextTab(); if (!tabToSelect) tabToSelect = tab.get_previousTab(); tabStrip.get_tabs().remove(tab); multiPage.get_pageViews().remove(pageView); if (tabToSelect) tabToSelect.set_selected(true); } /* ]]> */ </script> 

and in the lode page

  if (!Page.IsPostBack) { RadTab tab = new RadTab(); tab.Text = string.Format("New Page {0}", 1); RadTabStrip1.Tabs.Add(tab); RadPageView pageView = new RadPageView(); pageView.Height = new Unit("50px"); pageView.Width = new Unit("1300px"); RadMultiPage1.PageViews.Add(pageView); BuildPageViewContents(pageView, RadTabStrip1.Tabs.Count); RadTabStrip1.SelectedIndex = 0; } 
+4
source share
3 answers

This error may occur if you try to use a null object. In this code, quite a few things can return null : $find, findTabByText, getPageView, get_nextTab, get_previousTab , etc. I suggest you alert () everything before using it. So you will find what is null .

+3
source

You do not check any of these function calls to see if they really return something. One of them returns null , but your code does not notice this and is trying to use the result in the following expression.

Try this on Firefox with Firebug and you will probably get the best error messages.

+3
source

$ find may return null if you try to call it too early. Remember that ASP.NET AJAX controls are created during the Sys.Application.Init event. If you try to access them earlier (for example, in window.onload), $ find () will not work.

0
source

Source: https://habr.com/ru/post/1310981/


All Articles