We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

How to close an Dialog using a botton on the ContentURL

I am trying to close a Dialog Box from a submit button in the contentURL screen I using to populate my Dialog
On my main page I have.

@Html.EJ().Dialog("Dialog2").Title("Contact Admin").ContentType("iframe").ContentUrl(Url.Action("ContactAdmin2", "Help")).Width(900).Height(500).ShowOnInit(false).EnableResize(false).EnableModal(true)


Then on my ContentURL page I have the following

<input type="submit" value="Send to admin" class="btn btn-primary" />


I want to use my controller or javascript on ContactAdmin2 Screen.

Controller code:


[HttpPost]

public ActionResult ContactAdmin2(ContactAdminViewModel contactAdminViewModel, IEnumerable uploadbox)

{

..do some code

return Content("< script type='text/javascript' >window.close();< / script >");

return Content("");

//I have tried the following but it only closes the content window and not the dialog window.  Spaces in the script part is not part of the real code

}






4 Replies

AB Ashokkumar Balasubramanian Syncfusion Team October 11, 2019 10:33 AM UTC

Hi David, 
  
Thanks for contacting Syncfusion support. 
  
We checked the shared code. It seems you have set “contentType” as iframe for Dialog. Usually Dialog can be closed by invoking “close” method from Dialog instance, but this does not work in this case because you loaded the button as iframe content within the dialog. We cannot access iframe DOM element because the dialog is rendered in another page. 
  
Please refer to the following link: 
 
 
 
So, we suggest you set the contentType as “ajax” instead of iframe to overcome this issue. Please refer to the following code 
 
@{ 
@Html.EJ().Dialog("Dialog2").Title("Contact Admin").ContentType("ajax").ContentUrl(Url.Action("ContactAdmin2")).Width(900).Height(500).ShowOnInit(false).EnableResize(false).EnableModal(true) 
} 
 
 
[ContactAdmin2.cshtml] 
 
<input type="submit" value="Send to admin" class="btn btn-primary" onclick="OnClick()" /> 
<script> 
    function OnClick(args) { 
        var obj = $("#Dialog2").data("ejDialog"); 
        obj.close(); 
    } 
</script> 
 
  
Note: If you still wish to use contentType as “iframe” you need to close dialog using the default close action button present in the right end of Dialog. 
 
Please let us know, if you have any concern. 
 
Regards, 
Ashokkumar B. 



DH David Heidlebaugh October 11, 2019 01:41 PM UTC

Ashokkumar B,

Thank you for responding to my message.

I understand what you are saying.  My coworker and I found the same thing and we are using the close action button now of the dialog box.

Here is what the code looks like if anyone needs it.

return Content("<  script type='text/javascript' >window.parent.document.getElementById('Dialog2_closebutton').click();< / script >");

This works just once though because the system will clear my Dialog screen out and when I click it again my dialog box comes up blank

LayoutHtml

onclick="onclickBtn()" class="btn btn-link">Contact Admin

@Html.EJ().Dialog("Dialog2").Title("Contact Admin").ContentType("iframe").ContentUrl(Url.Action("ContactAdmin2", "Help")).Width(900).Height(500).ShowOnInit(false).EnableResize(false).EnableModal(true

<script>

     function onclickBtn() {

               var dialogObj = $("#Dialog2").data("ejDialog");

               dialogObj.open();


              }

script>

 
ContraAdmin2.cshtml
 <input type="submit" value="Send to admin" class="btn btn-primary" />


 
HelpController.cs
[HttpPost]

public ActionResult ContactAdmin2(ContactAdminViewModel contactAdminViewModel, IEnumerable uploadbox)

{

..do some code





return Content("<  script type='text/javascript' >window.parent.document.getElementById('Dialog2_closebutton').click();< / script >");






}


 







DH David Heidlebaugh October 11, 2019 04:25 PM UTC

Figure it out.
In my script of layout.cshtml I first clear the iframe contentUrl and then add it back in.  This will refresh the screen.

Here the code.

function onclickBtn() {

$("#Dialog2").ejDialog({contentType: "iframe", contentUrl: "" });

$("#Dialog2").ejDialog({contentType: "iframe", contentUrl: "../Help/ContactAdmin2" });

$("#Dialog2").ejDialog("open");

}




KR Keerthana Rajendran Syncfusion Team October 14, 2019 09:31 AM UTC

Hi David,  

Thanks for the updates. We are glad that the issue has been resolved in your end. Please get back to us if you need further assistance on this.  

Regards, 
Keerthana.  


Loader.
Live Chat Icon For mobile
Up arrow icon