首页 > 解决方案 > Creating Radwindow in code behind and avoiding postback on radwindow close

问题描述

I can create a radwindow on the server side. Here is the code being executed on button click. The close button is created in the code behind too.

protected void OpenRW_Click(object sender, System.EventArgs e)
      {
        RadWindow window = new RadWindow();
        window.Modal = true;
        window.EnableViewState = false;
        window.VisibleOnPageLoad = true;
        window.Width = 300;
        window.Height = 300;

        window.VisibleOnPageLoad = true;
        window.Visible = true;
        window.DestroyOnClose = true;
        window.Behaviors = Telerik.Web.UI.WindowBehaviors.Move;

        window.ID = "Popup";

        //create close button here

        Button closebt = new Button();
        closebt.Visible = true;
        closebt.Text = "Close";

        closebt.OnClientClick = "$find(\" <%= Popup.ClientID %> \").close(); return false;";



        closebt.Style.Add("position", "absolute");
        closebt.Style.Add("bottom", "5px");
        closebt.Style.Add("right", "10px");


        window.ContentContainer.Controls.Add(closebt);
        RadWindowManager1.Controls.Add(window);

    }

But for some reason when it gets closed it fires a unneeded postback. I've tried a whole bunch of things including setting the viewonpageload property to false and using scriptmanager to display the window, but this yields the same results. Any ideas on how I can get rid of this unnecessary postback would be greatly appreciated. thanks in advance.

标签: asp.nettelerik

解决方案


The issue was with DNN (dotnetnuke) reassigning the clientid. The clientid was rendering differently so the js wasn't recognizing the clientid that was being preemptively loaded on the postback which was throwing an exception in the browser and thus causing the extra postback on the window close. My work around was to use jquery to hide the div of the window by using the window class as an identifier and then remove the the modal overlay.

 closebt.OnClientClick += "$('.<yourwindowclass>').hide();$telerik.$(\".TelerikModalOverlay\").remove(); return false;";

I also interfaced with the telerik team on this issue. I should add their support is very good.

https://www.telerik.com/forums/creating-radwindow-on-server-side#FAxVzO4lYkC7jHDx21chOw


推荐阅读