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

Programmatic creation of the RadWindowManager (getting Microsoft JScript runtime error: 'null' is null or not an object)

3 Answers 110 Views
Window
This is a migrated thread and some comments may be shown as answers.
Vladimir Gosic
Top achievements
Rank 1
Vladimir Gosic asked on 01 Jul 2010, 04:29 PM
 Hello,

I am creating the RadWindowManager in the Page.Init event handler on every PostBack using the following code:

Dim cmdWindowManager As RadWindowManager = New RadWindowManager 
cmdWindowManager.ID = "CommandWindowManager" 
 
Dim cmdWindow As RadWindow = New RadWindow 
cmdWindow.ID = "CommandWindow" 
cmdWindow.ReloadOnShow = True 
cmdWindow.ShowContentDuringLoad = False 
cmdWindow.Modal = True 
cmdWindow.AutoSize = True 
cmdWindow.Width = Unit.Pixel(450) 
cmdWindow.Height = Unit.Pixel(150) 
 
cmdWindowManager.Windows.Add(cmdWindow) 
 
contentContainer.Controls.Add(cmdWindowManager) 

where contentContainer is an AspPanel in my ContentPage, which means I am using MasterPage also. I must add the RadWindowManager programmatic because it is done in a BasePage class from which all other content pages inherit.

I have tried many combination of the JavaScript that would show me the RadWindow, but I never got to see it shown. Here are two approaches that I tried (I am passing the RadWindowManager.ClientId to the function that generates the bellow JavaScripts).
The JavaScript I am adding everytime to the contentContainer (also on Page.Init) is:

function ShowEditForm(formUrl, formTitle) {  
var oWnd = window.radopen(formUrl, formTitle);  
return false;  
}  
  
function ShowInsertForm(formUrl, formTitle) {  
alert('test');  
var oWnd = $find(ctl00_ContentPlaceHolderMain_CommandWindowManager).GetWindowByName('CommandWindow');  
oWnd.SetUrl(formUrl);  
oWnd.Show(); 
return false;  
}   

and the code that I am adding to the same contentContainer after the Grid.ItemCommand event is:
' configure Client Script for Command Items 
Dim radCodeBlockAction As RadScriptBlock = New RadScriptBlock 
Dim script As New LiteralControl("<script type=""text/javascript"" language=""javascript""> " & Environment.NewLine & _ 
                                         String.Format(ACTION_FUNCTION_FORMAT, _ 
                                                       ActionFunction, _ 
                                                       ActionFormUrl, _ 
                                                       FormTitle) & Environment.NewLine & _ 
                                         "</script>"
 
' the result of String.Format is "ShowInsert('edit.aspx','CommandWindow')" 
 
radCodeBlockAction.Controls.Clear() 
radCodeBlockAction.Controls.Add(script) 
 
contentContainer.Controls.Add(radCodeBlockAction) 



So the code gets executed but client script debugger stops at:

var oWnd = window.radopen(formUrl, formTitle);  
or:
var oWnd = $find(ctl00_ContentPlaceHolderMain_CommandWindowManager).GetWindowByName('CommandWindow');


with the error: Microsoft JScript runtime error: 'null' is null or not an object.
Could you please give me a quick response.

Thank you in advance!

Regards,
Vladimir



3 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 06 Jul 2010, 11:40 AM
Hello Vladimir,

Try calling the script that opens the RadWindow at a later stage - for example you could use window.setTimeout(). I believe that the reason for the problem is that you are trying to execute radopen() before the RadWindow / RadWindowManager is fully rendered on the page. Such behavior is expected because ASP.NET AJAX controls (including our RadControls) are created in Sys.Application.Init() - you can verify that by examining the HTML dump of a page with ASP.NET AJAX controls in it.


Regards,
Georgi Tunev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Vladimir Gosic
Top achievements
Rank 1
answered on 06 Jul 2010, 11:53 AM
Hello Georgi,

Thank you for your answer. I managed to resolve the issue myself, but forgot to post the solution here. I concluded that the script was being called to early, so I used:

Sys.Application.add_load(function(){ShowInsertForm('edit.aspx','CommandWindow')}) 

and the RadWindow loads as expected.

I now have the issue that after the RadWindow is closed by using "GetRadWindow().close();" or using X on the window, and after that some control on the parent Page invokes PostBack I get a ViewState error stating that Control tree/count is invalid. I managed to temporarily bypass it by calling Response.Redirect to the Page itself on close, but I would like to use only Grid.Rebind(). Is this a common issue or should I post more details about the problem?

Regards,
Vladimir

0
Georgi Tunev
Telerik team
answered on 07 Jul 2010, 02:13 PM
Hello Vladimir,

I don't think this issue is related to the RadWindow control - I believe you would get the same behavior if you call the JavaScript function (that you call in RadWindow's OnClientClose) directly.
I don't know what exactly you do on the server in the postback, but in general such error occurs if you try to modify some controls - I suggest to check the exact error message in Google for more information on the subject.
In any case, I would suggest to consider using Ajax instead of postbacks. For example, if you are using RadAjax, you could use ajaxRequest() for calling server-side functions from the client.

All the best,
Georgi Tunev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Window
Asked by
Vladimir Gosic
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Vladimir Gosic
Top achievements
Rank 1
Share this question
or