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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to close an Dialog using a botton on the ContentURL

Thread ID:

Created:

Updated:

Platform:

Replies:

148229 Oct 10,2019 02:09 PM UTC Oct 14,2019 09:31 AM UTC ASP.NET MVC 4
loading
Tags: Dialog
David Heidlebaugh
Asked On October 10, 2019 02:15 PM UTC

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

}






Ashokkumar Balasubramanian [Syncfusion]
Replied On 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. 


David Heidlebaugh
Replied On 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 >");






}


 






David Heidlebaugh
Replied On 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");

}



Keerthana Rajendran [Syncfusion]
Replied On 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.  


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon