Dynamically open a radwindow defined in Javascript

前端 未结 2 1961
温柔的废话
温柔的废话 2021-01-14 13:28

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

Code

相关标签:
2条回答
  • 2021-01-14 14:04

    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%>");
    }
    
    0 讨论(0)
  • 2021-01-14 14:08

    Take a look here, it explains how to use the ScriptManager.RegisterStartupScript method: http://www.telerik.com/help/aspnet-ajax/window-troubleshooting-javascript-from-server-side.html. Note it the ScriptManager's method. Also look at the Sys.Application.Load event to prevent your code from executing too early.

    0 讨论(0)
提交回复
热议问题