This is a migrated thread and some comments may be shown as answers.

Javasxipt Error Msg - 'undefined' is null or not an object

3 Answers 341 Views
Window
This is a migrated thread and some comments may be shown as answers.
Ruth
Top achievements
Rank 1
Ruth asked on 05 Feb 2009, 07:40 AM
The following piece of code produce a javascript error"
Type.registerNamespace("Telerik.Web.UI"); 
Type.registerNamespace("Telerik.Web.UI.WindowManager"); 
function GetRadWindowManager(){ 
return Telerik.Web.UI.WindowManager.Manager; 
window.radalert=function(_1,_2,_3,_4){ 
var _5=GetRadWindowManager(); 
var _6=_5._getStandardPopup("alert",_1); 
if(typeof (_4)!="undefined"){ 
 

The error is in the bold line, and the msg is:"Microsoft JScript runtime error: 'undefined' is null or not an object"

It is related to popUpRadMsg. I call it on this way:
<body onload="msgAlert()">






</html>
.
.script goes under the </html>:
.





...
<script language="javascript" type="text/javascript"
    // This code must be in the master and cannot be moved to external js file. 
    // We use String comparsion instead of boolean, to keep the code valid. 
    // if (Convert.ToString(divDisplayMsg.Visible)).ToLower()  is accidently empty, no harm is done and the code is still valid. 
    function msgAlert() { 
        var toPopup = "<%=(Convert.ToString(divIsDisplayMsgVisible.Visible)).ToLower() %>"
        if (toPopup == "true") { 
            var displayMsgDiv = document.getElementById("<%=divDisplayMsg.ClientID %>"); 
             
            if (displayMsgDiv) { 
                var msg = displayMsgDiv.innerHTML
                //alert(msg); 
                popupRadMsg(msg); 
            }  
            //popupDisplayMsg(); 
 
        } 
    } 
</script> 
 
 

and on an attached JS file:
function popupRadMsg(msg){ 
            return radalert(msg, 500, 500); 
          } 

This alert is invoked depending on the visibility  of divDisplayMsg. this is set on the server side and allow me to control the popup msg (I can send text and info from server side to it).

Maybe you can tell why is this javascript error occurs?

(IE7, IE6, FF)

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 05 Feb 2009, 09:49 AM
Hi Ruth,

In ASP.NET AJAX environment, the ASP.NET AJAX controls (including RadControls for ASP.NET AJAX) are created after the page has been loaded. I assume that the problem here is that when you initially try to get a reference to the RadWindowManager, the control is still not fully rendered on the page and that is why getting the error. Try the pageLoad() function to call the msgAlert() function instead of attaching with onload of page body. The function pageLoad() is fired automatically by the MS AJAX client framework when the page is rendered completely. Try the code below and see whether it is working for you.

JavaScript:
<script language="javascript" type="text/javascript"
function pageLoad() 
    msgAlert(); 
</script> 

Thanks,
Shinu.
0
durga
Top achievements
Rank 1
answered on 20 Jul 2009, 10:57 PM
Hi,

I have the same javascript error message. I am tryign to open a new radwindow after postback from server side inside a user control.

protected

 

void btnAdd_Click(object sender, EventArgs e)

 

{
 

 

if

 

(!Page.ClientScript.IsStartupScriptRegistered("OpenCheckPopup"))

 

{

//Some code that needs to be run before calling script.

Page.ClientScript.RegisterStartupScript(Page.GetType(),

 

"OpenCheckPopup",

 

 

"<script type=\"text/javascript\">showcheck(" + ApplicationID + ");</script>");

 

}

 

}

In .aspx

 

 

function showcheck(applicationId) {

 

 

var param = 'addCheck.aspx?ApplicationID=' + applicationId;

 

showOtherWindow(param, 400, 400);

 

return false;

 

}

 

 

function showOtherWindow(url, height, width) {

 

 

if (window.radopen) {

 

 

var oWnd = window.radopen(null, "DialogWindow");

 

 

if (oWnd != null && url != null) {

 

oWnd.set_width(width);

oWnd.set_height(height);

oWnd.setUrl(url);

oWnd.reloadOnShow =

true;

 

oWnd.center();

oWnd.show();

}

}

}

I have defined the radwindowmanager in .aspx.

I think the page is not fully  loaded at this time so it fails to get the reference to radwidnowmanager.

How can I solve this issue?

Thanks,
Devi

0
Georgi Tunev
Telerik team
answered on 21 Jul 2009, 01:51 PM
Hi durga,

I believe that the following blog post will be of help:
http://blogs.telerik.com/blogs/posts/09-05-05/executing_javascript_function_from_server-side_code.aspx


Kind regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Window
Asked by
Ruth
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
durga
Top achievements
Rank 1
Georgi Tunev
Telerik team
Share this question
or