javascriptasp.netradwindow

Dynamically open a radwindow defined in Javascript


Objective:- From the server-side, I need to open a radwindow(defined in JavaScript of the aspx page) automatically on an IF condition.

Code used:-

In aspx page, I defined the radwindow as:-

<telerik:RadWindowManager Skin="WBDA" ID="AssetPreviewManager" Modal="true" 
EnableEmbeddedSkins="false" runat="server"  DestroyOnClose="true" Behavior="Close" 
style="z-index:8000">
    <Windows>   
        <telerik:RadWindow ID="DisclaimerAlertWindow" runat="server" Width="720px"    Height="220px" 
Modal="true" visibleStatusbar="false" VisibleTitlebar="false" keepInScreenBounds="true" title="Sourav">                                            
      </telerik:RadWindow>  
   </Windows>  
</telerik:RadWindowManager>

In JavaScript, a function is defined for opening the radwindow:-

function openRadWindow() 
     { 
        var oWnd = radopen('DisclaimerAlert.aspx, 'DisclaimerAlertWindow'); 
        oWnd.set_title('Access Denied !');  
        oWnd.Center(); 
        return false; 
     }

So on the server side of the aspx page, In the Page Load event an IF condition is checked and then I'm calling 'openRadWindow()' function as:-

protected void Page_Load(object sender, EventArgs e)
{
if (fieldValue == "False") 
{ 
 string xyz = "<script type='text/javascript' lang='Javascript'>openRadWindow();</script>"; 
 ClientScript.RegisterStartupScript(this.GetType(), "Window", xyz); 
}
}

Problem:-

But on running this, these JavaScript errors are coming:-

  1. Object doesn't support this property or method.
  2. 'undefined' is null or not an object

Please help how to achieve my objective. I am totally stuck.


Solution

  • Hi I want to share with you my solution to create RadWindow dialog in Javascript code only.

    We need to implement 2 methods: one for initializing RadWindow dialog, and the last one for recieving the arguments returned after closing the RadWindow. You can do what you want in this second step (e.x postback,...)

    Here is my code:

    Initializing RadWindow dialog:

        function openMyDialog(url, args) {
        var manageWindow = GetRadWindowManager();
        if (manageWindow) {
            var radWindow = manageWindow.open(url, "<your_dialog_name>");
            if (radWindow) {
                radWindow.set_initialBehaviors(Telerik.Web.UI.WindowBehaviors.None);
                radWindow.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move + Telerik.Web.UI.WindowBehaviors.Close + Telerik.Web.UI.WindowBehaviors.Resize);
                radWindow.setActive(true);
                radWindow.SetModal(true);
                radWindow.center();
                radWindow.set_visibleStatusbar(false);
                radWindow.set_keepInScreenBounds(true);
                radWindow.set_minWidth(640);
                radWindow.set_minHeight(480);
                radWindow.setSize(640, 480);
                radWindow.set_destroyOnClose(true);
                radWindow.add_close(closeMyDialog);//after closing the RadWindow, closeMyDialog will be called
                radWindow.argument = args;//you can pass the value from parent page to RadWindow dialog as this line
            }
        }
    }
    

    Closing the RadWindow dialog:

    function closeMoveProjectDialog(sender, args) {
        var objArgs = args.get_argument();
        //objArgs variable stored the values returned from the RadWindow
        //you can use it for your purpose
    }
    

    How to call this? You can put the open method into your expected method. In my side, I have a method as shown below and I will call the RadWindow as this way:

    function ShowForeignKeyFrontEditSingle(param1, param2){
        var url = "ForeignKeyFrontEditSingle.aspx";
        var objArgs = new Array();
        objArgs[0] = param1;
        objArgs[1] = param2;
    
        openMyDialog(url, objArgs);
        return;
    }
    

    Of course, you have to declare a RadWindowManager control

    function GetRadWindowManager() {
        return $find("<%=your_radwindow_manager_control.ClientID%>");
    }