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

Creating Radwindow on Server side

8 Answers 264 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Jesse
Top achievements
Rank 1
Veteran
Jesse asked on 14 Mar 2020, 03:00 PM

I can create a radwindow on the server side. Here is the code-

 

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.CssClass="imageloader";
        window.VisibleOnPageLoad = true;
        window.Visible = true;
        window.DestroyOnClose = true;
        window.Behaviors = Telerik.Web.UI.WindowBehaviors.Move;
        window.Title = Title;
        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 things including setting the 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.

8 Answers, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 17 Mar 2020, 02:55 PM

Hi Jesse,

The page postbacks because there is a JS error when hitting the dialog button:

Uncaught TypeError: Cannot read property 'close' of null
    at HTMLInputElement.onclick (Default6.aspx:81)

 

 

Here is how to fix the problem:

        closebt.OnClientClick = "$find('" + window.ClientID + "').close(); return false;";

 

Regards,
Rumen
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Jesse
Top achievements
Rank 1
answered on 17 Mar 2020, 09:06 PM

Hi Rumen,

 

Thanks for the help. It seems this solution only works when I put the code directly into the button click event, but when I call it from an instance of class I still get a postback on a window close. So I updated the code to recreate this situation since the code I posted last time was from smaller project I was using to try to isolate what was causing the postback.

 

  protected void OpenRW_Click(object sender, System.EventArgs e)
    {
      
      

        RadWindow window = FormController.ShowRadWindowSaveOrErrorConfirmation(300, 300, "fubar");

        
        RadWindowManager1.Controls.Add(window);

    }

public class FormController{

 public static RadWindow ShowRadWindowSaveOrErrorConfirmation(int height, int width, String Title)
    {
        //create window here
        RadWindow window = new RadWindow();
        window.Modal = true;
        window.EnableViewState = false;
        window.VisibleOnPageLoad = true;
        window.Width = width;
        window.Height = height;
        window.CssClass = "imageloader";

        
        window.DestroyOnClose = true;
        window.Behaviors = Telerik.Web.UI.WindowBehaviors.Move;
        window.Title = "fubar";
        ///window.ID = "Popup";
        //window.NavigateUrl = "../RadForm.aspx?mess=" + AM.Body;
        ///window.OnClientClose = "OnClientClose";
        //create close button here

        Button closebt = new Button();

        closebt.OnClientClick = "$find('" + window.ClientID + "').close(); return false;";
       
        closebt.Text = "Close";



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

   
      
        window.ContentContainer.Controls.Add(closebt);

        return window;


    }

 

 

}

 

 

So calling from a static function in class seems to be causing the postback on a window close. If you have any other suggestions that would be great. Thanks again.

0
Rumen
Telerik team
answered on 17 Mar 2020, 10:19 PM

Hi Jessy,

The new code generates the same JS error:

Uncaught TypeError: Cannot read property 'close' of null

because the window.ID is commented out and the window.ClientID does not return the correct string id to supply the $find method.

In order to fix the issue uncomment the

window.ID = "Popup";

line and you can call for the test:

closebt.OnClientClick = "alert(" + window.ClientID + "); $find('" + window.ClientID + "').close(); return false;";

Regards,
Rumen
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Jesse
Top achievements
Rank 1
answered on 18 Mar 2020, 05:54 PM

Hi Rumen,

 

You're right, but in my main project it still posts back. I've narrowed the cause down to DotNetNuke which is installed in the main project. In the browser debugger I noticed the control id was coming up as 'dnn_ctr1812_TF_InstructorProfile_Popup' for client id and in visual server side debugger as well. So I tried this

 

 

OnClientClick = "$find('dnn_ctr1812_TF_InstructorProfile_Popup').close(); return false;"; in button and setting visualOnPageLoad property to false then I ran this script on the server side to display it.

protected void OpenRW_Click(object sender, System.EventArgs e)
    {
      
      

        RadWindow window = FormController.ShowRadWindowSaveOrErrorConfirmation(300, 300, "fubar");

        
        RadWindowManager1.Controls.Add(window);
  string script = "function f(){$find(\"" + window1.ClientID + "\").show(); Sys.Application.remove_load(f);}Sys.Application.add_load(f);";
           ScriptManager.RegisterStartupScript(Page, Page.GetType(), "key", script, true);
    }

This closed without postback, but it won't work unless I run this script I added from the server side setting visualOnPageload to false,. Obviously I do not want to use dnn prefix id to close the window- since it could be different on everyone else's machine and I would prefer not to have to have this extra script for displaying the window... If you have a work around for this that would be great. I do not know if many of your customers use DNN, but I did see some posts from those that were. Perhaps you or someone else on your team is familiar with this issue. Thanks again.

0
Rumen
Telerik team
answered on 19 Mar 2020, 09:09 AM

Hi Jessy,

My advice is to set the ID of the window from the server and to review the following blog post which should help you out to get the generate/predict the id from the client-side: 

The difference between ID, ClientID and UniqueID.

We do not support DNN from years and my recommendation is to look at the DNN forums or ask their support on how the IDs are generated in DNN.

Best Regards,


Rumen
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Jesse
Top achievements
Rank 1
answered on 19 Mar 2020, 05:50 PM

Hi Rumen,

 

Thanks for all the help. It seems I've found a work around of sorts using jquery to hide by using the class of the div as an identifier.

 

closebt.OnClientClick += @"$('.imageloader').hide();  return false;";

 

But I am unable to hide its modality. Would you or anyone else know of a method I can use to hide its modality- or set the property to false on clientside- so that there is no postback. Thanks in advance.

 

Jesse

 

 

 

 

0
Rumen
Telerik team
answered on 19 Mar 2020, 11:15 PM

Hi Jessy,

You can remove the modality by calling:

$telerik.$(".TelerikModalOverlay").remove();

 

Regards,
Rumen
Progress Telerik

Get quickly onboarded and successful with UI for ASP.NET AJAX with the Virtual Classroom technical trainings, available to all active customers. Learn More.
0
Jesse
Top achievements
Rank 1
answered on 20 Mar 2020, 01:54 PM

Hi Rumen,

Thanks! That works!  For those of you who are following this thread in the future and are having this issue with DNN, using jquery in your client side logic to hide the window by its assigned  div class (css)  and then  removing the modal overlay like this:

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

 

seems to be a viable work around for closing the radwindow on client side with no postback

 

Jesse

Tags
General Discussions
Asked by
Jesse
Top achievements
Rank 1
Veteran
Answers by
Rumen
Telerik team
Jesse
Top achievements
Rank 1
Share this question
or